Message-ID: <CAM_vjum0C1YiJRYuTrWDsxF43cj3ryUe9hhEKws3pBEThaM2zA@mail.gmail.com>
Date: 2011-11-02T18:11:34Z
From: Sarah Goslee
Subject: Sum with condition
In-Reply-To: <1320237862644-3972839.post@n4.nabble.com>
Hi,
On Wed, Nov 2, 2011 at 8:44 AM, Celine <bellard.celine at gmail.com> wrote:
> CELLCD AreaProtected
> ? 8928 ? ? ?52.39389
> ? 8928 ? ? ?41.91511
> ? 8929 ? ? ?21.21975
> ? 8929 ? ? ?63.65925
> ? 8930 ? ? ?26.08547
> ? 8930 ? ? ?14.04602
You'll need to figure out how you want it to be combined with the
original data frame, since there can't be empty cells, but:
> dput(testdata)
structure(list(CELLCD = c(8928L, 8928L, 8929L, 8929L, 8930L,
8930L), AreaProtected = c(52.39389, 41.91511, 21.21975, 63.65925,
26.08547, 14.04602)), .Names = c("CELLCD", "AreaProtected"), class =
"data.frame", row.names = c(NA,
-6L))
>
> aggregate(testdata$AreaProtected, by=list(CELLCD=testdata$CELLCD), FUN="sum")
CELLCD x
1 8928 94.30900
2 8929 84.87900
3 8930 40.13149
--
Sarah Goslee
http://www.functionaldiversity.org