tab: Returns cross tabulation

View source: R/tab.R

tabR Documentation

Returns cross tabulation

Description

Returns cross tabulation

Usage

tab(x, ..., wt = NULL, na.rm = FALSE, sort = TRUE)

Arguments

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

Value

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

Examples

# 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)

statar documentation built on Aug. 19, 2023, 5:09 p.m.