Skip to content
Prev 316779 / 398506 Next

Script for conditional sums of vectors

try this:

a <- c(1,1,1,1,1,1,2,2,2,2,2,2)
b <- c(1,1,1,2,3,4,1,1,2,2,3,4)
c <- c(400,200,300,100,500,300,200,100,500,400,200,100)
DF <- data.frame(a, b, c)

with(DF, tapply(c, list(a, b), sum))


I hope it helps.

Best,
Dimitris
On 2/4/2013 10:29 AM, Benjamin Gillespie wrote: