[R] sum specific rows in a data frame

arnaud Gaboury arnaud.gaboury at gmail.com
Wed Apr 14 17:43:37 CEST 2010


Thank you for your help. The best I have found is to use the ddply function.

> pose
          DESCRIPTION QUANITY CLOSING.PRICE
1       WHEAT May/10        1        467.75
2       WHEAT May/10        1        467.75
3       WHEAT May/10        1        467.75
4       WHEAT May/10        1        467.75
5 COTTON NO.2 May/10        1         78.13
6 COTTON NO.2 May/10        1         78.13
7 COTTON NO.2 May/10        1         78.13

> library(plyr)
> op=ddply(pose, c("DESCRIPTION","CLOSING.PRICE"),summarise, POSITION=
sum(QUANITY))
> op
          DESCRIPTION CLOSING.PRICE POSITION
1 COTTON NO.2 May/10          78.13        3
2       WHEAT May/10         467.75        4

Op is a data.frame object.The trick is done!



***************************
Arnaud Gaboury
Mobile: +41 79 392 79 56
BBM: 255B488F



More information about the R-help mailing list