Re: [R] removing rows from matrix

From: <Richard.Cotton_at_hsl.gov.uk>
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 cols.to.remove <- apply(m, 2, function(x) any(x < 50 | x > 1000)) m[,!cols.to.remove]

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

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}

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. 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive