filter rows by a function over values of each row, data.table
问题 Switch from data.frame syntax to data.table syntax is still not smooth for me. I thought the following thing should be trivial, but no. What I am doing wrong here: > DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9) > DT x y v 1: a 1 1 2: a 3 2 3: a 6 3 4: b 1 4 5: b 3 5 6: b 6 6 7: c 1 7 8: c 3 8 9: c 6 9 I want something like this: cols = c("y", "v") # a vector of column names or indexes DT[rowSums(cols) > 5] # Take only rows where # values at colums y and v satisfy a