Skip to content
Prev 316184 / 398506 Next

Removal of columns from matrix where all values of the column are identical.

Benjamin Ward (ENV <B.Ward <at> uea.ac.uk> writes:
the column contains only one
I think you want Matrix[, apply(Matrix,2,function(x) { length(unique(x))>1 ) } ]

  The anonymous function tests whether there is more than one unique value.
apply() runs it on every column and returns a logical vector.  The [ , ]
indexing selects the corresponding columns ...