NA
values are present, valid percentages (calculated excluding NA
values). A fully-featured alternative to table()
.tabyl
can be called in two ways:
1) It can simply be called on a vector, like tabyl(mtcars$gear)
.
2) A data.frame can be provided as the first argument, followed by an unquoted column name to tabulate. This enables passing in a data.frame from a %>%
pipeline, like mtcars %>% tabyl(gear)
.
tabyl(...)
"tabyl"(vec, sort = FALSE, show_na = TRUE, ...)
"tabyl"(.data, ...)
tabyl
on a data.frame.n
.NA
values should be displayed, along with an additional column showing valid percentages.vec
should be an unquoted column name.default
: Create a frequency table from a vector. data.frame
: Create a frequency table from a data.frame,
supplying the unquoted name of the column to tabulate.
# Calling on a vector:
val <- c("hi", "med", "med", "lo")
tabyl(val)
tabyl(mtcars$cyl, sort = TRUE)
# Passing in a data.frame using a pipeline:
library(dplyr) # to access the pipe operator
mtcars %>% tabyl(cyl)
# illustrating show_na functionality:
my_cars <- rbind(mtcars, rep(NA, 11))
tabyl(my_cars$cyl)
tabyl(my_cars$cyl, show_na = FALSE)
Run the code above in your browser using DataLab