I am looking to subset a data table recursively, by changing the index of the column z AND at the same time filter rows based on some %in% based vector.
dt <- setDT(copy(diamonds))
dt <- setDT(data.frame(lapply(dt, as.character), stringsAsFactors=FALSE))
z=4
subset_by <- unique(dt[,z])[1:2]
### obviously does not work
###dt1<-dt[ z %in% subset_by]
I am looking for the most memory-efficient operation to do this and I am sure there is a way without using colnames, but I just cannot find it. I looked at a lot of posts, with this beign the most relevant
data.tableafter converting to data.frame in the 2nd line. You needdt[z %in% subset_by,]- akrununique(dt[[z]])[1:2]- akrun%inoperator - J. Doe.i1 <- dt[, .I[.SD[[1]] %in% subset_by],.SDcols = z] ; dt[i1]- akrun