Skip to content

removing columns

3 messages · nuncio m, Uwe Ligges, David Winsemius

#
On 03.05.2011 13:16, nuncio m wrote:
Xnew <- X[ , as.logical(colSums(X)), drop=FALSE]

Uwe Ligges
#
On May 3, 2011, at 4:24 AM, Uwe Ligges wrote:

            
A counter-example:

X <- matrix(c(1,1,1,-1,0,1,1,1,1),3)

A fix:
 > Xnew <- X[ , as.logical(colSums(abs(X))), drop=FALSE]
 > Xnew
      [,1] [,2] [,3]
[1,]    1   -1    1
[2,]    1    0    1
[3,]    1    1    1
David Winsemius, MD
Heritage Laboratories
West Hartford, CT