[R] remove columns containing all zeros (or other value)

Jim Lemon jim at bitwrit.com.au
Thu Jan 15 11:21:03 CET 2009


How about:

remove.constant.values<-function(x,MARGIN,value2remove) {
 is.constant.line<-function(x,value2remove) { return(any(x!=value2remove)) }
 return(unlist(apply(x,MARGIN,is.constant.line,value2remove)))
}

x[,remove.constant.values(x,2,0)]

Jim




More information about the R-help mailing list