[datatable-help] Subsetting columns in data.table

Berto cubalibro at gmail.com
Fri Nov 16 19:32:22 CET 2012


Hi Matthew, thanks for the quick reply.

I want to find all the rows that are above a threshold for one column (e.g.
y>=3) and below another threshold for all the rest (e.g. v<=7&w<=7, for a
threshold<7).

Once I have this subsetting, I'd like to use the sum function (e.g. sum(y),
by=x).

I know how to do it for a low number of columns, specifiying all columns
names<threshold:

DT[y>=3&*v<=7&w<=7*,sum(y), by=x] 
 
which gives the expected result:

    x V1 
1: a  9 
2: b  3 

But if the number of columns grows, I can't specify all columns anymore,
maybe should I use column names?

cols <- cols[names(DT) %in% "y" == FALSE] #column names excluding the one
with higher threshold

Hope to be clearer this time, otherwise please let me know!




--
View this message in context: http://r.789695.n4.nabble.com/Subsetting-columns-in-data-table-tp4649736p4649779.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list