Re: [R] removing the rows with negative elements

2010-01-05 Thread Petr PIKAL
Another option is x[rowSums(x<0)==0, ] but beware of floating point if your numbers can be near zero. Regards Petr r-help-boun...@r-project.org napsal dne 06.01.2010 06:52:48: > Thank you! > > On Jan 6, 2010 12:31am, Peter Ehlers wrote: > > x[apply(x,1,function(x)all(x>=0)),] > > > >

Re: [R] removing the rows with negative elements

2010-01-05 Thread Dimitris Rizopoulos
try also this: x <- matrix(c(2,-1,-2,3,5,6,-3,7,4,2,1,0), 4, 3) x[!rowSums(x < 0), ] Best, Dimitris farida...@gmail.com wrote: Hello All, I would like to remove the entire row, if there is any negative element in that row. What is the best way to do that? For example, x<-matrix(c(2,-1,

Re: [R] removing the rows with negative elements

2010-01-05 Thread faridamsb
Thank you! On Jan 6, 2010 12:31am, Peter Ehlers wrote: > x[apply(x,1,function(x)all(x>=0)),] > -Peter Ehlers > Simon Blomberg wrote: > x[-which(x > but I'm sure someone will suggest an easier way. > Simon. > On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote: > Hello A

Re: [R] removing the rows with negative elements

2010-01-05 Thread Peter Ehlers
x[apply(x,1,function(x)all(x>=0)),] -Peter Ehlers Simon Blomberg wrote: x[-which(x < 0, arr.ind=TRUE)[,1],] but I'm sure someone will suggest an easier way. Simon. On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote: Hello All, I would like to remove the entire row, if there is

Re: [R] removing the rows with negative elements

2010-01-05 Thread Simon Blomberg
x[-which(x < 0, arr.ind=TRUE)[,1],] but I'm sure someone will suggest an easier way. Simon. On Wed, 2010-01-06 at 05:13 +, farida...@gmail.com wrote: > Hello All, > > I would like to remove the entire row, if there is any negative element in > that row. What is the best way to do that? >