dt_count.Rd
Count the numbers of observations within groups
dt_count(dt_, ..., na.rm = FALSE, wt = NULL)
the data table to uncount
groups
should any rows with missingness be removed before the count? Default is FALSE
.
the wt assigned to the counts (same number of rows as the data)
A data.table with counts for each group (or combination of groups)
library(data.table)
dt <- data.table(
x = rnorm(1e5),
y = runif(1e5),
grp = sample(1L:3L, 1e5, replace = TRUE),
wt = runif(1e5, 1, 100)
)
dt_count(dt, grp)
#> grp N
#> 1: 1 33214
#> 2: 2 33417
#> 3: 3 33369
dt_count(dt, grp, na.rm = TRUE)
#> grp N
#> 1: 1 33214
#> 2: 2 33417
#> 3: 3 33369
dt_count(dt, grp, na.rm = TRUE, wt = wt)
#> grp N
#> 1: 1 1676721
#> 2: 2 1681753
#> 3: 3 1675696