[R] how to drop rows from a data.frame

From: Peter Wilkinson <pwilkinson_at_videotron.ca>
Date: Thu 01 Jul 2004 - 13:57:38 EST


here is a snippet of data where I would like to drop all rows that have zeros across them, and keep the rest of the rows while maintaining the row names (1,2,3, ...10). The idea here is that a row of zeros is an indication that the row must be dropped. There will never be the case where there is a row(of n columns) with less than 5 zeros in this case(n zeros

I am unsure how to manipulate the data frame to drop rows whiles keeping row names.

Peter

the data (imagine separated by tabs):

       SEKH0001 SEKH0002 SEKH0003 SEKH0004 SEKH0005
[1,] 256.1139 256.1139 256.1139 256.1139 256.1139
[2,] 283.0741 695.1000 614.5117 453.0342 500.1436
[3,] 257.3578 305.0818 257.3578 257.3578 257.3578
[4,] 0.0000 0.0000 0.0000 0.0000 0.0000
[5,] 0.0000 0.0000 0.0000 0.0000 0.0000
[6,] 0.0000 0.0000 0.0000 0.0000 0.0000
[7,] 0.0000 0.0000 0.0000 0.0000 0.0000
[8,] 257.0000 257.0000 257.0000 257.0000 257.0000

[9,] 305.7857 2450.0417 335.5428 305.7857 584.2485
[10,] 0.0000 0.0000 0.0000 0.0000 0.0000

what I want it to look like:

       SEKH0001 SEKH0002 SEKH0003 SEKH0004 SEKH0005
[1,] 256.1139 256.1139 256.1139 256.1139 256.1139
[2,] 283.0741 695.1000 614.5117 453.0342 500.1436
[3,] 257.3578 305.0818 257.3578 257.3578 257.3578
[8,] 257.0000 257.0000 257.0000 257.0000 257.0000
[9,] 305.7857 2450.0417 335.5428 305.7857 584.2485



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 01 14:02:31 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 08:52:15 EST