[R] Sum with Conditions

jimdare jamesdare26 at gmail.com
Fri Jul 24 04:02:50 CEST 2009


Thanks very much :)


Daniel Malter wrote:
> 
> length(datasetname$Events[datasetname$Length<28 &
> datasetname$Method%in%c(1,2,3) ...additional conditions...      , ]
> returns
> the number of rows
> sum(datasetname$Events[datasetname$Length<28 &
> datasetname$Method%in%c(1,2,3) ...additional conditions...      , ]
> returns
> the sum of the Events variable given your conditions
> 
> does that work for you?
> Daniel
> 
> -------------------------
> cuncta stricte discussurus
> -------------------------
> 
> -----Ursprüngliche Nachricht-----
> Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
> Auftrag von jimdare
> Gesendet: Thursday, July 23, 2009 8:07 PM
> An: r-help at r-project.org
> Betreff: [R] Sum with Conditions
> 
> 
> Dear R-Users,
> 
> I have a huge data set (172,696 rows) that is set out in the following
> way:
> 
> Area | Length | Species | Method | Date | Events	
> 
> I want to sum the number of Events if:
> 
> Length < 28                                AND
> Species is NOT "X" ,"Y", or "Z"       AND
> Method is either "1" ,"2", or "3"       AND
> Date is between 31/12/08 AND 1/02/09 (i.e. JAN 09) 
> 
> Is there an easy way to do this?
> 
> Your help is much appreciated.
> 
> James  
> 
>       
> --
> View this message in context:
> http://www.nabble.com/Sum-with-Conditions-tp24636551p24636551.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Sum-with-Conditions-tp24636551p24637520.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list