Re: [R] removing rows from matrix

From: <>
Date: Fri, 02 May 2008 12:55:06 +0100

> Hi, I have a problem regarding matrix handeling. I am working with
> a serie of matrixes containing several columns. Now I would like to
> delete those rows of the matrixes,that in one of the columns contain
> values less than 50 or greater than 1000.

Try this:
m <- matrix(runif(150, 0, 1050), nrow=10); m <- apply(m, 2, function(x) any(x < 50 | x > 1000)) m[,!]

It's well worth learning how to use apply, and its variants (tapply, sapply etc.); they come in very useful.


Mathematical Sciences Unit

ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 02 May 2008 - 11:58:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 02 May 2008 - 12:30:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive