Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] colA:colB notation for by #1395

Closed
franknarf1 opened this issue Oct 14, 2015 · 1 comment
Closed

[Request] colA:colB notation for by #1395

franknarf1 opened this issue Oct 14, 2015 · 1 comment
Assignees
Milestone

Comments

@franknarf1
Copy link
Contributor

Looking at this SO question, it seems useful:

require(data.table)
dat <- setDT(structure(list(ID = c(97330L, 118619L, 101623L, 202626L, 182925L, 
    179278L), IV1 = c(3L, 0L, 2L, 0L, 1L, 1L), DV1 = c(0L, 0L, 0L, 
    0L, 1L, 0L), DV2 = c(0L, 0L, 0L, 0L, 0L, 0L), DV3 = c(0L, 0L, 
    0L, 0L, 0L, 0L), DV4 = c(0L, 0L, 0L, 0L, 0L, 0L), DV5 = c(0L, 
    1L, 0L, 0L, 0L, 0L), DV6 = c(1L, 1L, 0L, 0L, 0L, 0L), DV7 = c(0L, 
    0L, 0L, 0L, 0L, 0L)), .Names = c("ID", "IV1", "DV1", "DV2", "DV3", 
    "DV4", "DV5", "DV6", "DV7"), class = "data.frame", row.names = c(NA, 
    -6L)))

dat[, sum(IV1), by=.(DV1, DV2, DV3, DV4, DV5, DV6, DV7)] # does work
dat[, sum(IV1), by=DV1:DV7]                              # should work

    #    DV1 DV2 DV3 DV4 DV5 DV6 DV7 V1
    #1:   0   0   0   0   0   1   0  3
    #2:   0   0   0   0   1   1   0  0
    #3:   0   0   0   0   0   0   0  3
    #4:   1   0   0   0   0   0   0  1
@DavidArenburg
Copy link
Member

I was thinking pretty much the same when saw this question :) I think there is a related FR for this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants