a1 <- data.table(id=c(1,1,1,1,2,2,2,3,3),
var=c("6402","1","6302","3","6406","6406","2","1","1"))
b1 <- data.table(var=c("6402","6406","6302"),
txt=c("A","B","A"))
mm <- b1[a1,on=.(var)]
dcast(mm,id~txt,function(x) any(!is.na(x)),fill=NA)
desired_output <- data.table(id=c(1,2,3),
A=c(T,F,F),
B=c(F,T,F))
How can I get the desired_output? Somehow the aggregating function seems to be playing games with me...