Skip to content

Exclude when sd=0

4 messages · Chris Burns, David Winsemius, Jorge I Velez +1 more

#
On May 23, 2012, at 8:44 PM, Chris Burns wrote:

            
mtx[ , as.logical(apply(mtx, 2, sd))]
#
Assuming you mean that the column is constant so that the sd is 0

test <- matrix(rnorm(50), nrow=10, ncol=5)
test[,2] <- 1
test[,4] <- 2
# test[,which(apply(test, 2, sd) > 0)] could fail on rounding errors
Test2 <- test[, which(apply(test, 2, sd) > 1e-10)] 


----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352