tab: Efficient tabulation

Description Usage Arguments Value Examples

View source: R/tab.R

Description

Produces a tabulation: for each unique group from the variable(s), tab shows the number of observations with that value, proportion of observations with that value, and cumulative proportion, in descending order of frequency. Accepts data.table, tibble, or data.frame as input. Efficient with big data: if you give it a data.table, tab uses data.table syntax.

Usage

1

Arguments

df

A data.table, tibble, or data.frame.

...

A column or set of columns (without quotation marks).

by

A variable by which you want to group observations before tabulating (without quotation marks).

round

An integer indicating the number of digits for proportion and cumulative proportion.

Value

Tabulation (frequencies, proportion, cumulative proportion) for each unique value of the variables given in ... from df.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# data.table
library(data.table)
library(magrittr)
a <- data.table(varname = sample.int(20, size = 1000000, replace = TRUE))
a %>% tab(varname)

# tibble
library(dplyr)
b <- tibble(varname = sample.int(20, size = 1000000, replace = TRUE))
b %>% tab(varname, round = 1)

# data.frame
c <- data.frame(varname = sample.int(20, size = 1000000, replace = TRUE))
c %>% tab(varname)

tabulator documentation built on Jan. 13, 2021, 12:56 p.m.