statar (version 0.4.0)

tab: Returns cross tabulation

Description

Returns cross tabulation

Usage

tab(x, ...)

tab_(x, vars = NULL, i = NULL, w = NULL, na.rm = FALSE, sort = sort)

Arguments

x
a vector or a data.frame
...
Variable to include. If length is two, a special cross tabulation table is printed although the a long data.frame is always (invisibly) returned.
vars
Used to work around non-standard evaluation.
i
Condition to apply function on certain rows only
w
Frequency weights. Default to NULL.
na.rm
Remove missing values. Default to FALSE
sort
Boolean. Default to TRUE

Value

  • a data.frame sorted by variables in ..., and with a columns "n", "Percent", and "Cum." for counts.

Examples

Run this code
library(dplyr)
N <- 1e2 ; K = 10
df <- data_frame(
  id = sample(c(NA,1:5), N/K, TRUE),
  v1 =  sample(1:5, N/K, TRUE)
)
tab(df[["id"]])
tab(df, id)
df %>% group_by(id) %>% tab()
df %>% group_by(id) %>% tab(v1)
tab(df, id, i = id>=3)

Run the code above in your browser using DataCamp Workspace