calc_tabyl | R Documentation |
This is a simple wrapper around the tabyl
function from the janitor
package. So rather than writing a bunch of lines over and over again, I
made this shortened function to make my life easier. Since the first
argument takes a data frame or a tibble, this function is pipeable.
calc_tabyl(data, ..., show_na = TRUE, show_missing_levels = TRUE)
data |
A data frame or tibble. |
... |
the column arguments to |
show_na |
should counts of |
show_missing_levels |
should counts of missing levels of factors be displayed? These will be rows and/or columns of zeroes. Useful for keeping consistent output dimensions even when certain factor levels may not be present in the data. |
Returns a data.frame with frequencies and percentages of the tabulated variable(s). A 3-way tabulation returns a list of data.frames.
calc_tabyl(mtcars, cyl)
calc_tabyl(mtcars, cyl, gear)
calc_tabyl(mtcars, cyl, gear, am)
# or using the %>% pipe
mtcars %>%
calc_tabyl(cyl, gear)
# illustrating show_na functionality:
my_cars <- rbind(mtcars, rep(NA, 11))
my_cars %>% calc_tabyl(cyl)
my_cars %>% calc_tabyl(cyl, show_na = FALSE)
# Calling on a single vector not in a data.frame:
val <- c("hi", "med", "med", "lo")
calc_tabyl(val)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.