[R] subsetting a data.frame based on a specific group of columns
Assa Yeroslaviz
frymor at gmail.com
Fri Nov 6 11:40:26 CET 2015
Hi,
I have a data frame with multiple columns, which are belong to several
groups
like that:
X1 X2 X3 Y1 Y2 Y3
1232 357 23 0 9871 72
0 71 9 811 795 743
43 919 1111 0 76 14
I would like to filter such rows out, where the sums in one group is lower
than a specifc value. For example, I would like to set all the values in a
group of cloums to zero, if the sum in one group is less than 100
In my example table I would like to set the values in the second row for
the three X-columns to 0, so that the table looks like that:
X1 X2 X3 Y1 Y2 Y3
1232 357 23 0 9871 72
0 0 0 811 795 743
43 919 1111 0 0 0
the same apply also for the Y-values in the last column.
Is there a more efficient way of doing it than going row by row and use the
apply function on each of the subgroups I have in the columns?
thanks
Assa
[[alternative HTML version deleted]]
More information about the R-help
mailing list