Skip to content

Instantly share code, notes, and snippets.

View tchakravarty's full-sized avatar

Tirthankar Chakravarty tchakravarty

View GitHub Profile
@tchakravarty
tchakravarty / AggregateDataTable.R
Created January 23, 2015 18:10
Aggregation with column names specified via regular expressions
dtX = data.table(idx1 = rep(1:3, 100),
idx2 = sample(1:4, size = 10, replace = TRUE, prob = rep(0.25, 4)),
v1 = rnorm(10),
v2 = rnorm(10),
v3 = rnorm(10),
x1 = LETTERS[1:10])
dtXAgg = dtX[, j = lapply(.SD, mean),
by = list(idx1, idx2),
.SDcols = grep("^v", names(dtX), value = TRUE)]