dt.count: dt.count

Description Usage Arguments Note Source Examples

View source: R/dt.count_dt.filter_dt.select.R

Description

A function that counts the number of rows that meets the qualification such as filter and the by (grouping variables). If both filter and the grouping variables are not set up, then it will return the number of rows.

Usage

1
2
3
4
5
6
7
dt.count(
  dat,
  the.filter = NULL,
  grouping.variables = NULL,
  grouping.type = "keyby",
  count.name = "N"
)

Arguments

dat

a data.frame object.

the.filter

a character value, logical value, or expression stating the logical operations to be performed in filtering the data prior to calculating the.function. Defaults to "NULL" unless specified.

grouping.variables

a character vector specifying variables to group by in performing the computation. Only values that exist in names(dat) will be used.

grouping.type

a character value specifying whether the grouping should be sorted (keyby) or as is (by). Defaults to keyby unless "by" is specified.

count.name

a character value specifying the name of the column of counts in the resulting table. Defaults to "N" unless specified.

Note

the data.frame dat will be converted to a data.table object to facilitate adding the new column by reference (e.g. efficiently with regard to the usage of memory)

Source

DTwrappers::create.filter.expression

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 age.name = "Age"
 income.name = "Income"
 region.name = "Region"
 gender.name = "Gender"

 dt.count(dat = formulaic::snack.dat)

 dt.count(dat = formulaic::snack.dat,
 grouping.variables = c(region.name, gender.name))

 dt.count(dat = formulaic::snack.dat,
 the.filter = "Age > 65",
 grouping.variables = c(region.name, gender.name),
 count.name = "Records with Age > 65")

 dt.count(dat = formulaic::snack.dat,
 the.filter = 'get(age.name) > 20',
 grouping.variables = c(age.name,income.name),
 grouping.type = 'keyby', count.name = "counts")

dachosen1/DTwrappers documentation built on Dec. 25, 2019, 8:04 a.m.