tab | R Documentation |
Returns cross tabulation
tab(x, ..., wt = NULL, na.rm = FALSE, sort = TRUE)
x |
a vector or a data.frame |
... |
Variable(s) to include. If length is two, a special cross tabulation table is printed although a long data.frame is always (invisibly) returned. |
wt |
Frequency weights. Default to NULL. |
na.rm |
Remove missing values. Default to FALSE |
sort |
Boolean. Default to TRUE |
a data.frame sorted by variables in ..., and with columns "Freq.", "Percent", and "Cum." for counts.
# setup
library(dplyr)
N <- 1e2 ; K = 10
df <- tibble(
id = sample(c(NA,1:5), N/K, TRUE),
v1 = sample(1:5, N/K, TRUE)
)
# one-way tabulation
df %>% tab(id)
df %>% tab(id, wt = v1)
# two-way tabulation
df %>% tab(id, v1)
df %>% filter(id >= 3) %>% tab(id)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.