dt_count {maditr}R Documentation

Additional useful functions

Description

Usage

dt_count(data, ..., weight = NULL, sort = FALSE, name = "n")

dt_add_count(data, ..., weight = NULL, sort = FALSE, name = "n")

dt_top_n(data, n, by, order_by = NULL)

Arguments

data

data.table/data.frame data.frame will be automatically converted to data.table.

...

variables to group by.

weight

optional. Unquoted variable name. If provided result will be the sum of this variable by groups.

sort

logical. If TRUE result will be sorted in desending order by resulting variable.

name

character. Name of resulting variable.

n

numeric. number of top cases. If n is negative then bottom values will be returned.

by

list or vector of grouping variables

order_by

unquoted variable name by which result will be sorted. If not specified, defaults to the last variable in the dataset.

Value

data.table

Examples


data(mtcars)

# dt_count
dt_count(mtcars, am, vs)
dt_add_count(mtcars, am, vs, name = "am_vs")[] # [] for autoprinting

# dt_top_n
dt_top_n(mtcars, 2, by  = list(am, vs))
dt_top_n(mtcars, 2, order_by = mpg, by  = list(am, vs))

[Package maditr version 0.8.4 Index]