An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120523/9e1be9e7/attachment.pl>
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:
How do I trim a matrix to exclude columns that have no standard deviation?
mtx[ , as.logical(apply(mtx, 2, sd))]
David Winsemius, MD West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120524/59032596/attachment.pl>
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.