Reputation: 10324
In a R script I have a DataFrame in the format:
V1 V2 V3 V4
1 HIAT1 3.917271e-05 4.278916e-05 3.793761e-05
2 SASS6 2.008972e-06 1.890391e-06 2.168946e-06
3 TRMT13 4.397712e-06 4.724036e-06 4.009512e-06
Where the first column is a String name and the following are numeric values. The total number of values is not known a priori, but depends on the dataset provided as input to the script.
I want to extract only the rows for which the sum(or average) of elements from the second to the last is greater than a certain threshold.
How to do that in R-style?
Upvotes: 2
Views: 4138
Reputation: 887118
We can use rowSums/rowMeans
of the numeric columns, get a logical vector using >
and subset the rows.
thresh <- 0.0001
df1[rowSums(df1[,-1])> thresh,]
Upvotes: 7