[R] removing rows from matrix
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Fri May 2 13:55:06 CEST 2008
> 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}}
More information about the R-help
mailing list