[R] Combining some duplicated rows & summing one of their column
jholtman at gmail.com
Sun Nov 6 21:00:32 CET 2011
Since you did not supply a subset of data, or indicate if you wanted
all the other values transformed in some ways, here is a simple use of
tapply to get your data with respect to 'catch'. If this not what you
wanted, you need to be more clear in your request and also give some
hints as to what you tried.
> x <- data.frame(EID = sample(10, 20, TRUE), catch = 1:20)
> tapply(x$catch, x$EID, sum)
1 2 3 4 5 6 7 8 9 10
18 12 20 5 54 19 20 4 56 2
On Sun, Nov 6, 2011 at 2:23 PM, Aurelie Cosandey Godin <godina at dal.ca> wrote:
> Dear list,
> I have this dataframe:
>  "EID" "X" "Y" "trip" "tow" "catch" "effort" "depth"
>  "season"
> Where some of my unique ID "EID" appears more than once in 162 cases.
>  162
> I would like to combined each replicate EID together and sum their "catch". I've been trying a few things with the plyr package... but can't find a rather straightforward command.
> Any tips would be much appreciated! Thank you very much!
> Aurelie Cosandey-Godin
> Ph.D. student, Department of Biology
> Industrial Graduate Fellow, WWF-Canada
> Dalhousie University | Email: godina at dal.ca
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
More information about the R-help