[R] Eliminating columns that sum to zero

Douglas Bates bates at stat.wisc.edu
Sun Aug 24 19:06:53 CEST 2008


On Sun, Aug 24, 2008 at 11:54 AM, Ben Bolker <bolker at ufl.edu> wrote:
>
>
> Wade Wall <wade.wall <at> gmail.com> writes:
>
>> I am trying to look for a way to eliminate columns that sum to zero. Any
>> help would be appreciated.
>
>  x_without_zero_cols <- x[,colSums(x)!=0]

Of course, depending on the nature of the columns, you may want to use
a relative comparison for column sums that are close to zero.
Checking for exact equality on the results of floating point
computations often produces surprising false negatives.

>  If you want to make some return for this helpful advice,
> you could take this information and add it to the "R tips" section
> of the R wiki ( http://wiki.r-project.org ).
>
>  cheers
>    Ben Bolker
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list