An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20040828/2c68539b/attachment.pl
removing invariant columns from a matrix
3 messages · Moises Hassan, Peter Dalgaard, Spencer Graves
"Moises Hassan" <mhassan at scitegic.com> writes:
I'm looking for an efficient way of removing zero-variance columns from a large matrix. Any suggestions?
A[,apply(A,2,var)>0]
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Both the previous solutions seem to assume a numeric matrix. How
about the following:
A <- array(letters[c(rep(1, 13), rep(2, 13), 1:26)], dim=c(13, 5))
A[, apply(A, 2, function(x)any(x[-1] != x[-length(x)]))]
A[, apply(A, 2, function(x)any(x[-1] != x[-length(x)])]
enjoy. spencer graves
Peter Dalgaard wrote:
"Moises Hassan" <mhassan at scitegic.com> writes:
I'm looking for an efficient way of removing zero-variance columns from a large matrix. Any suggestions?
A[,apply(A,2,var)>0]