# Selecting elements within 1 standard deviation from a Matrix

#### sak

##### New Member
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

#### Dason

##### Ambassador to the humans
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)]
})