[R] Conditional Row Sum
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Apr 20 20:54:49 CEST 2006
Using the built in data.frame iris sum each of the first 4 columns for
each value of the 5th column.
rowsum(iris[,-5], iris[,5])
On 4/20/06, Sachin J <sachinj.2006 at yahoo.com> wrote:
> Hi,
>
> How can I accomplish this in R. Example:
>
> R1 R2
> 3 101
> 4 102
> 3 102
> 18 102
> 11 101
>
> I want to find Sum(101) = 14 - i.e SUM(R1) where R2 = 101
> Sum(102) = 25 - SUM(R2) where R2 = 102
>
> TIA
> Sachin
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list