You're on the right track with cut
:
dat <- data.frame(Depth = 0:10,
Percent = c(0.4, 0.1, 0.5, 0.2, 0.1, 0.3, 0.9, 0.3, 0.2, 0.2, 0.8))
cuts <- cut(dat$Depth, breaks=c(0, 1, 6, 9, 11), right=FALSE)
Then you can use aggregate
:
aggregate(dat$Percent, list(cuts), sum)
Or as a oneliner:
aggregate(dat$Percent,
list(cut(dat$Depth,
breaks=c(0, 1, 6, 9, 11),
right=FALSE)),
sum)