DT <- data.table(num=c("20031111","1112003","23423","2222004"),y=c("2003","2003","2003","2004"))
> DT
num y
1: 20031111 2003
2: 1112003 2003
3: 23423 2003
4: 2222004 2004
I want to compare the two cell content, and perform an action based on the boolean value. for instance, if "num" matches the year, create a column x holding that value. I thought about subsetting based on grep, and that works, but naturally checks the whole column every time which seems wasteful
DT[grep(y,num)] # works with a pattern>1 warning
I could apply() my way but perhaps there's a data.table way?
Thanks
grep.