I would like to take unique rows from the data.table, given the subset of columns and condition in i. What is the best way to do this? ("Best" in terms of computational speed and short or readable syntax)
set.seed(1)
jk <- data.table(c1 = sample(letters,60,replace = TRUE),
c2 = sample(c(TRUE,FALSE),60, replace = TRUE),
c3 = sample(letters,60, replace = TRUE),
c4 = sample.int(10,60, replace = TRUE)
)
Let's say I would like to find unique combinations c1and c2, where c4equal to 10. I can come up with a couple of ways to do this, but I'm not sure which is optimal. Regardless of whether the columns to extract are the key or not, it can also be important.
jk[c4 >= 10, TRUE, keyby = list(c1,c2)]
jk[c4 >= 10, TRUE, keyby = list(c1,c2)][,V1 := NULL]
jk[c4 >= 10, , keyby = list(c1,c2)]
jk[c4 >= 10, unique(.SD), .SDcols = c("c1","c2")]