On Feb 21, 2011, at 6:05 PM, David Winsemius wrote:


On Feb 21, 2011, at 4:03 PM, IgnacioQM wrote:

I need to filter my data:
I think its easy but i'm stuck so i'll appreciate some help:

I have a data frame with 14 variables and 6 million rows. About half of this rows have a value of "0" in 12 variables (the other two variables always have values). How can I delete the rows in which all 12 variables have the
value of "0".

example (from my data, variable 14 is missing):

1783 81 85 78 89 71 97 76 66 88
95     95     98  -57.48258
1784 81 86 79 90 71 97 77 66 88
95     95     98  -57.43768
1785 81 86 79 90 71 98 77 66 89
95     94     98  -57.39278
1786 0 0 0 0 0 0 0 0 0
0      0      0  -57.34788
1787 0 0 0 0 0 0 0 0 0
0      0      0  -57.30298
1788 80 86 80 90 72 98 78 66 88
93     93     96  -57.25808
1789 77 83 78 88 70 95 76 63 86
91     90     93  -57.21318
1790 77 84 79 89 70 96 76 64 87
91     90     93  -57.16828

I would need to delete rows 1786 & 1787.

something along the lines of:

dfrm[ -apply(dfrm, 1, function(x) all(x==0) ), ]

Looking at a second time, I see the qualification of only the first 12 rows, so

dfrm[ -apply(dfrm[, 1:12], 1, function(x) all(x==0) ), ]

Email obscured that compounded by the fact that you didn't post a reproducible data object.



I tried subset with variable1>"0"&variable2>"0", but it wasn't useful 'cause it only took the rows that didn't have a 0 in any of the variables; I only
need in ALL of the variables simultaneously.

Thanks,

Ignacio



David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to