Skip to content

delete all columns with all values equal to zero

5 messages · Frederico Mestre, Sarah Goslee, Peter Alspach +1 more

#
Hi,

On Thu, Dec 22, 2011 at 4:54 PM, Frederico Mestre
<mestre.frederico at gmail.com> wrote:
If this, then apply() and sum() are useful.

If the problem in the subject line (NOT the same thing), all() rather
than sum().

A reproducible example will get you usable code.

Sarah

  
    
#
Tena koe Frederico

Something like

yourDF[, apply(yourDF, 2, sum)!=0]

HTH ....

Peter Alspach

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Frederico Mestre
Sent: Friday, 23 December 2011 10:55 a.m.
To: r-help at r-project.org
Subject: [R] delete all columns with all values equal to zero

Hello all:

 

I'm sure this is quite simple, but I tried several options and I still can't
get I right.

 

I've got a data.frame and I want to delete all columns of which the sum is
zero.

 

Any ideas? Thanks,

 

Frederico Mestre

 



______________________________________________
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.

The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.