[R] question about sum of (column) elements in R
Berend Hasselman
bhh at xs4all.nl
Tue Dec 4 11:24:16 CET 2012
On 04-12-2012, at 08:59, T Bal wrote:
> Hi,
> I have the following data:
>
> 0 12
> 1 10
> 1 4
> 1 6
> 1 7
> 1 13
> 2 21
> 2 23
> 2 20
> 3 18
> 3 17
> 3 16
> 3 27
> 3 33
> 4 11
> 4 8
> 4 19
> 4 16
> 4 9
>
>
> In this data file I would like to sum the numbers of second column which
> belong to the same number in the first column.
> So the output would be:
>
> 0 12
> 1 40
> 2 64
> 3 111
> etc.
Using Pascal's test object you can also use aggregate
aggregate(test$V2,by=list(test$V1),FUN=sum)
Berend
More information about the R-help
mailing list