[R] sum two columns with same value

smu ml at z107.de
Sat Oct 17 11:39:26 CEST 2009


On Sat, Oct 17, 2009 at 09:36:50AM +0200, Alfredo Alessandrini wrote:
> Hi,
> 
> I've two dataframe:
> 
> > snag_totale
>   AREA   snag_ha
> 1    2  1.628128
> 2    3 10.274249
> 3    4  2.778503
> 4    5 73.764307
> 5    7 12.015985
> > log_totale
>   AREA    log_ha
> 1    1  22.29846
> 2    2  17.16889
> 3    3  48.80377
> 4    4 144.18996
> 5    5  70.30962
> 6    6  61.81850
> 7    7  13.24876
> >
> 
> How can I obtain a new data.frame, by the sum of value "snag_ha" +
> "log_ha" in the same "AREA"?


one way would be:

tmp <- merge(snag_totale, log_totale, by="AREA")
tmp$sum <- tmp$snag_ha + tmp$log_ha

regards, 
    stefan




More information about the R-help mailing list