[R] removing the rows with negative elements

Simon Blomberg s.blomberg1 at uq.edu.au
Wed Jan 6 06:27:27 CET 2010


 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 +0000, faridamsb at 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,-2,3,5,6,-3,7,4,2,1,0), 4, 3)
> 
> the returning matrix should look like
> 
> [,1] [,2] [,3]
> [1,] 2 5 4
> [2,] 3 7 0
> 
> 
> Thank you in advance,
> 
> FM
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
School of Biological Sciences
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

Statistics is the grammar of science - Karl Pearson



More information about the R-help mailing list