In the process of data merging, I often end up with columns of lists (for example, a row in the left table has several matches in the right table)
define
DT = data.table(x=list(c(1,2),c(3,4,5)),y=list(c(T,T),c(T,F,T)),z=c(1,2),N=c(1L,2L))
- Is it possible to change aka
update xin place x[y]?
I can do this, but not update (and look ugly) like:
DT1 = DT[,list(x=list(unlist(x)[unlist(y)])),by=N]
DT = cbind(DT[,x:=NULL],DT1[,list(x)])
y z N x
1: TRUE,TRUE 1 1 1,2
2: TRUE,FALSE,TRUE 2 2 3,5
Now suppose I define mySet = c(1,5)and want to verify that the column valuesx %in% mySet
How can i do this?
y z N x isInMySet
1: TRUE,TRUE 1 1 1,2 TRUE,FALSE
2: TRUE,FALSE,TRUE 2 2 3,5 FASLE,TRUE
source
share