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

Peter Wilkinson pwilkinson at videotron.ca
Thu Jul 1 06:29:48 CEST 2004


You right its a matrix (I ran an is.matrix() on my object).

Thanks,

Peter


At 12:13 AM 7/1/2004, Patrick Connolly wrote:
>On Wed, 30-Jun-2004 at 11:57PM -0400, Peter Wilkinson wrote:
>
>|> 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
>
>I'm curious to know how you got those row names.  I suspect you really
>have a matrix.
>
>If it were a dataframe, it would behave exactly how you are reqesting
>-- depending on how you got rid of rows 4:7.
>
>Try as.data.frame(<whatever.your.data.is.now>)
>
>Then deleting the rows will 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
>
>
>HTH
>
>
>--
>Patrick Connolly
>HortResearch
>Mt Albert
>Auckland
>New Zealand
>Ph: +64-9 815 4200 x 7188
>~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
>I have the world`s largest collection of seashells. I keep it on all
>the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright
>~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~




More information about the R-help mailing list