[datatable-help] subsetting by second key

G See gsee000 at gmail.com
Sun Jun 15 17:44:58 CEST 2014


Hi,

I want to subset a data.table using only its second key, which is
demonstrated here
http://stackoverflow.com/questions/15597685/subsetting-data-table-by-2nd-column-only-of-a-2-column-key-using-binary-search/15597713#15597713

However, I need to subset with more than one value in the secondary key

Is this warning expected? What exactly is it telling me?

    library(data.table)
    DT <- data.table(iris, key="Species,Petal.Width")
    DT[J(unique(Species), c(1.5, 2.0)), nomatch=0L]
    #   Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
    #1:          6.0         2.2          5.0         1.5 virginica
    #2:          6.3         2.8          5.1         1.5 virginica
    #Warning message:
    #In as.data.table.list(i) :
    #  Item 2 is of size 2 but maximum size is 3 (recycled leaving a
remainder of 1 items)


It looks like I can get what I want with either of these; can you
confirm that both of these will always return the same result?

    DT[Petal.Width %in% c(1.5, 2.0)]  # vector scan
    DT[CJ(unique(Species), c(1.5, 2.0)), nomatch=0L]


Thanks,
Garrett


More information about the datatable-help mailing list