Created
January 23, 2015 18:10
-
-
Save tchakravarty/6645d7c05262372690c2 to your computer and use it in GitHub Desktop.
Aggregation with column names specified via regular expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment