I have a datatable as below:
library(data.table)
dt <- data.table(
id = c(1:3),
string = list(c("tree", "house", "star"),
c("house", "tree", "dense forest"),
c("apple", "orange", "grapes"))
)
From this I wanted to get the rows which contains "tree" in the list string column. So I tried
dt["tree" %in% string]
Empty data.table (0 rows) of 2 cols: id,string
dt["tree" %in% unlist(string)]
id string
1: 1 tree,house,star
2: 2 house,tree,dense forest
3: 3 apple,orange,grapes
I am not sure which part I am doing it wrong.I just need id 1 and 2 to be returned.Any help is appreciated.