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

Peter Wilkinson pwilkinson at videotron.ca
Thu Jul 1 06:46:54 CEST 2004


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 at 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




More information about the R-help mailing list