[R] Exclude when sd=0

David L Carlson dcarlson at tamu.edu
Thu May 24 19:23:05 CEST 2012


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

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Chris Burns
> Sent: Wednesday, May 23, 2012 7:45 PM
> To: r-help at r-project.org
> Subject: [R] Exclude when sd=0
> 
> How do I trim a matrix to exclude columns that have no standard
> deviation?
> 
> Thanks,
> 
> Chris
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list