This will put those vectors into a list for you
Code:dat <- matrix(rnorm(100), ncol = 10) lapply(seq(ncol(dat)), function(i){ x <- dat[,i] x[x >= mean(x)-sd(x) & x <= mean(x)+sd(x)] })
Hi guys,
I have a matrix of 7 columns and each of these columns represent different variables. I want to create 7 new vectors and each will just have elements within 1 standard deviation across mean. So, each vector would be of different dimension. My idea will work but I am sure there are smarter ways to do it. I am thinking about running a for loop on each column and extracting elements which fall within 1 standard deviation across mean for respective column.
Thanks
This will put those vectors into a list for you
Code:dat <- matrix(rnorm(100), ncol = 10) lapply(seq(ncol(dat)), function(i){ x <- dat[,i] x[x >= mean(x)-sd(x) & x <= mean(x)+sd(x)] })
"His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich
sak (03-05-2013)
Thanks for quick reply!!
|
|