Code Functions and Arguments Flashcards
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?
if(!require(pacman)) install.packages(“pacman”)
pacman:p_load(janitor)
The function [BLANK] will give you the number of rows and columns in a dataset (e.g., for “ebola_sierra_leone” dataset).
dim(ebola_sierra_leone)
Using the [BLANK] function gives you a tabular summary of the common values for a categorical variable.
inspect_cat
To extract a single variable/column from a dataset (e.g., “ebola_sierra_leone”), use the [BLANK] operator.
$ (e.g. ebola_sierra_leone$age)
To create a frequency table on the ebola_sierra_leone dataset for the district and age variables, a useful function to use is:
tabyl(ebola_sierrra_leone, district, age)
Which function can you use to save plots to images with a specific file name? Use an example.
ggsave()
Ex: ggsave (filename = “output/categorical?plot.png”, plot = categ_vars_plot)
[BLANK] is good for showing very large tables in HTML by giving your audience the option to scroll through the tables.
reactable
To check the class of the age vector, you would type:
class(age)
Create an improved version of a data frame called data_epi (hint: tidyverse package).
tibble_epi <- as_tibble(data_epi)
This function can be used to import data and will automatically give you a tibble.
read_csv