With the data set below, how can I write a data.table call, subsets this table and returns the entire customer ID and its associated orders for this customer, if this customer ever bought SKU 1?
The expected result should return a table that excludes cid 3 and 5 for this condition and each row for clients matching sku == 1.
I’m stuck because I don’t know how to write a “contains” statement, == literal only returns the sku matching condition ... I am sure there is a better way.
library("data.table")
df<-data.frame(cid=c(1,1,1,1,1,2,2,2,2,2,3,4,5,5,6,6),
order=c(1,1,1,2,3,4,4,4,5,5,6,7,8,8,9,9),
sku=c(1,2,3,2,3,1,2,3,1,3,2,1,2,3,1,2))
dt=as.data.table(df)