Try this:
with(DF, rowsum(quantity, identifier))
On Thu, Dec 2, 2010 at 2:24 PM, chris99 wrote:
>
> I am trying to aggregate data in column 2 to identifiers in col 1
>
> eg..
>
> take this>
>
> identifier quantity
> 1 10
> 1 20
> 2
Nice thing about R is there are a number of ways to do things:
> x
identifier quantity
1 1 10
2 1 20
3 2 30
4 1 15
5 2 10
6 3 20
> require(sqldf)
> sqldf('select identifier, sum(quantity) as quantity from x
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=
see also tapply()
e.g.
a<-c(1,1,1,2,2,2,3,3,3)
b<-c(10,10,10,15,15,15,20,20,20)
c.dat<-data.frame(a,b)
tapply(c.dat[,2],c.dat[,1],sum)
Mike
On Thu, Dec 2, 2010 at 10:33 AM, Ivan Calandra wrote:
> see ?aggregate, and ?summaryBy (in package doBy)
> I think ddply (in package plyr) could also do
see ?aggregate, and ?summaryBy (in package doBy)
I think ddply (in package plyr) could also do the job
Ivan
Le 12/2/2010 17:24, chris99 a écrit :
I am trying to aggregate data in column 2 to identifiers in col 1
eg..
take this>
identifier quantity
1 10
1
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 q
6 matches
Mail list logo