Re: [R] removing columns

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Tue, 03 May 2011 06:55:19 -0700

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

>
>
> On 03.05.2011 13:16, nuncio m wrote:
>> Hi list,
>>
>> I have a matrix with all elements of some columns are zeroes. Is it
>> possible to remove these columns:
>
>
> Xnew <- X[ , as.logical(colSums(X)), drop=FALSE]

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

>
> Uwe Ligges
>
>
>> and create a new matrix
>> nuncio

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 05 May 2011 - 06:25:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive