data.table - r %in% operator behavior for data table factors? -
i can't seem %in% operator behave data table factor columns. know i'm missing secret syntax data tables, can't find it... i've searched over.
here's tiny example illustrating pain. of course simple answer use data frames, have large data set benefits features of data tables.
> <- data.table(c1=factor(c(1,2,3))) > c1 1: 1 2: 2 3: 3 > '2' %in% a[,1,with=f] [1] false > 2 %in% a[,1,with=f] [1] false and works expect data frames...
> b <- data.frame(c1=factor(c(1,2,3))) > '2' %in% b[,1] [1] true any appreciated....
a[,1,with=f] data.table , not vector b[,1]. documented.
a data.table list , help("%in%") says "lists converted character vectors". so, i'd guess happens (but it's hidden in c source code of match):
as.character(a[,1,with=f]) #[1] "1:3" you can select data.table columns efficiently [[:
'2' %in% a[[1]] #[1] true
Comments
Post a Comment