Code Functions and Arguments Flashcards

1
Q

At the start of an R script, we would like to install and load the package called {janitor}. What code chunk is recommended to have in your script?

A

if(!require(pacman)) install.packages(“pacman”)

pacman:p_load(janitor)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The function [BLANK] will give you the number of rows and columns in a dataset (e.g., for “ebola_sierra_leone” dataset).

A

dim(ebola_sierra_leone)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Using the [BLANK] function gives you a tabular summary of the common values for a categorical variable.

A

inspect_cat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

To extract a single variable/column from a dataset (e.g., “ebola_sierra_leone”), use the [BLANK] operator.

A

$ (e.g. ebola_sierra_leone$age)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

To create a frequency table on the ebola_sierra_leone dataset for the district and age variables, a useful function to use is:

A

tabyl(ebola_sierrra_leone, district, age)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which function can you use to save plots to images with a specific file name? Use an example.

A

ggsave()

Ex: ggsave (filename = “output/categorical?plot.png”, plot = categ_vars_plot)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

[BLANK] is good for showing very large tables in HTML by giving your audience the option to scroll through the tables.

A

reactable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

To check the class of the age vector, you would type:

A

class(age)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create an improved version of a data frame called data_epi (hint: tidyverse package).

A

tibble_epi <- as_tibble(data_epi)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

This function can be used to import data and will automatically give you a tibble.

A

read_csv

How well did you know this?
1
Not at all
2
3
4
5
Perfectly