Sanjana Haralalka
Sanjana Haralalka

Reputation: 75

month wise cumulative sum

i have a data which is of the form :

month  price  name
1       200   xyz
1       300   abc
2       500   xyz
3       300   abc
4       400   cde
5       200   cde
5       100   abc
5       200   xyz

i want to create a cumulative sum graph month wise. Can anyone please help me with that?

Upvotes: 2

Views: 877

Answers (1)

Aditya Sihag
Aditya Sihag

Reputation: 5167

try:

ts.plot(cumsum(as.vector(unlist(tapply(df$price,df$month,sum)))),
        main="cumulative month wise",
        xlab="month",ylab="cumulative",lty=3,col="purple",type="o")

Upvotes: 2

Related Questions