一个月的累积总和

时间:2013-02-13 12:28:10

标签: r

我有一个以下形式的数据:

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

我想明智地创建一个月累积总和图。谁能帮帮我呢?

1 个答案:

答案 0 :(得分:2)

尝试:

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")