Hi:

One (of many) ways is to use the aggregate() function in base R:

df <- data.frame(g = rep(LETTERS[1:5], each = 5), y = rnorm(25))
aggregate(y ~ g, data = df, FUN = sum)
  g          y
1 A -1.3165949
2 B  1.9850015
3 C -0.6460323
4 D -1.6459293
5 E  6.7001807

HTH,
Dennis


On Sun, Feb 13, 2011 at 8:32 PM, Jonathan Salerno <jdsale...@ucdavis.edu>wrote:

> This is a seemingly simple problem, but I'm unable to make any progress.  I
> have a large dataset, within it there is a column of location names, some
> of
> which repeat; the adjacent column lists values for each location name.  I
> need to sum the values which correspond to the same location name,
> returning
> a matrix of the columns containing the location name and the corresponding
> sum of values.  Thanks very much for any assistance.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to