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

Peter Wilkinson pwilkinson at videotron.ca
Thu Jul 1 05:57:38 CEST 2004


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




More information about the R-help mailing list