Message-ID: <069BB987-B1C8-4515-AFF8-8F40CD940752@xs4all.nl>
Date: 2012-12-04T10:24:16Z
From: Berend Hasselman
Subject: question about sum of (column) elements in R
In-Reply-To: <CAOeUc7ujS2N5aMmCVJ=iJXK+ta_F81NvuK9zY4Lt1zMX46caQA@mail.gmail.com>
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