Skip to content

[Request] colA:colB notation for by #1395

@franknarf1

Description

@franknarf1

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions