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

From: Peter Wilkinson <pwilkinson_at_videotron.ca>
Date: Thu 01 Jul 2004 - 14:46:54 EST

Thanks for everyone's help, there seems to be many ways of solving the problem that work well.

Peter

At 12:36 AM 7/1/2004, Gabor Grothendieck wrote:

>Assuming all the entries are non-negative and non-NA this will do it:
>
> DF[rowSums(DF) > 0,]
>
>
>
>Peter Wilkinson <pwilkinson <at> videotron.ca> writes:
>
>:
>: 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



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:50:18 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:38 EST