Skip to content

FR: assign names to CJ() like data.table() does #1596

@franknarf1

Description

@franknarf1

I frequently do

DT[CJ(colA = colA, colB = colB, unique=TRUE), on=c("colA","colB")]
# to complete missing levels

# or 
DT[, CJ(colA = colA, colB = colB, unique=TRUE)][!DT, on=c("colA","colB")]
# to identify missing levels
# http://stackoverflow.com/a/36065607/1191259

It would be nice if I could get away with writing colA and colB fewer times. The FR here is for

CJ(colA, colB, unique=TRUE, names=TRUE) 

to infer the names colA and colB, perhaps using whatever method is used by data.frame() and data.table() (make.names?).

(The name repetition could be reduced further if on=.Icols were a thing, I suppose, but I'll leave that for a separate FR.)

SO posts to update...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions