monkeychump@hushmail.com
2003-Jul-22 17:53 UTC
[R] Matrix manipulation - dropping rows based on a query
I have a matrix with some very funky data. I want to drop the columns with a mean > 1 (for instance). #Example: my.mat <- matrix(rnorm(100, 0, 3), nrow = 10) #I know I can get the row means: apply(my.mat,1, mean) I think I need to get a vector that has those rows > 1 my.mat[-rows>1,] The actual querry is much more complicated but this gives an approximation. Thanks. Promote security and make money with the Hushmail Affiliate Program:
James MacDonald
2003-Jul-22 18:15 UTC
[R] Matrix manipulation - dropping rows based on a query
tst <- apply(my.mat, 2, mean) < 1 my.mat[,tst] Will return only columns with mean < 1 Jim James W. MacDonald Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623>>> <monkeychump at hushmail.com> 07/22/03 01:53PM >>>I have a matrix with some very funky data. I want to drop the columns with a mean > 1 (for instance). #Example: my.mat <- matrix(rnorm(100, 0, 3), nrow = 10) #I know I can get the row means: apply(my.mat,1, mean) I think I need to get a vector that has those rows > 1 my.mat[-rows>1,] The actual querry is much more complicated but this gives an approximation. Thanks. Promote security and make money with the Hushmail Affiliate Program: ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
James MacDonald wrote:> tst <- apply(my.mat, 2, mean) < 1... and rowMeans(my.mat) < 1 will be faster, but perhaps not working for the requested "more complicated query". Uwe Ligges> my.mat[,tst] > > Will return only columns with mean < 1 > > Jim > > > > James W. MacDonald > Affymetrix and cDNA Microarray Core > University of Michigan Cancer Center > 1500 E. Medical Center Drive > 7410 CCGC > Ann Arbor MI 48109 > 734-647-5623 > > >>>><monkeychump at hushmail.com> 07/22/03 01:53PM >>> > > > I have a matrix with some very funky data. I want to drop the columns > with a mean > 1 (for instance). > #Example: > my.mat <- matrix(rnorm(100, 0, 3), nrow = 10) > > #I know I can get the row means: > apply(my.mat,1, mean) > > I think I need to get a vector that has those rows > 1 > > my.mat[-rows>1,] > > The actual querry is much more complicated but this gives an > approximation. > > Thanks. >