[R] Help summarizing R data frame
Patrick Hausmann
patrick.hausmann at uni-bremen.de
Thu Dec 2 17:55:24 CET 2010
Here are some examples with tapply, aggregate, ddply:
x <- read.table("clipboard", head=TRUE)
with(x, tapply(quantity, identifier, sum))
aggregate(x$quantity, by=list(x$identifier), sum)
aggregate(quantity ~ identifier, data = x, sum)
library(plyr)
ddply(x, .(identifier), summarise, quantity=sum(quantity))
HTH
Patrick
Am 02.12.2010 17:24, schrieb chris99:
>
> I am trying to aggregate data in column 2 to identifiers in col 1
>
> eg..
>
> take this>
>
> identifier quantity
> 1 10
> 1 20
> 2 30
> 1 15
> 2 10
> 3 20
>
> and make this>
>
> identifier quantity
> 1 45
> 2 40
> 3 20
>
>
> Thanks in advance for your help!
More information about the R-help
mailing list