[R] removing rows from matrix

Richard.Cotton at hsl.gov.uk
2008-05-02T11:55:06Z

>  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}}