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