tab: Returns cross tabulation

Description Usage Arguments Value Examples

View source: R/tab.R

Description

Returns cross tabulation

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 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 Jan. 13, 2021, 9:33 p.m.