Skip to content
Prev 311633 / 398502 Next

Using cumsum with 'group by' ?

Hi,
No problem.
One more method if you wanted to try:
library(data.table)
dat2<-data.table(dat1)
dat2[,list(x,time,Cumsum=cumsum(x)),list(id)]
?# ? id? x? time Cumsum
?#1:? 1? 5 12:01????? 5
?#2:? 1 14 12:02???? 19
?#3:? 1? 6 12:03???? 25
?#4:? 1? 3 12:04???? 28
?#5:? 2 98 12:01???? 98
?#6:? 2 23 12:02??? 121
?#7:? 2? 1 12:03??? 122
?#8:? 2? 4 12:04??? 126
?#9:? 3? 5 12:01????? 5
#10:? 3 65 12:02???? 70
#11:? 3 23 12:03???? 93
#12:? 3 23 12:04??? 116


A.K.



----- Original Message -----
From: TheRealJimShady <james.david.smith at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, November 22, 2012 12:27 PM
Subject: Re: [R] Using cumsum with 'group by' ?

Thank you very much, I will try these tomorrow morning.

On 22 November 2012 17:25, arun kirshna [via R]
<ml-node+s789695n4650459h55 at n4.nabble.com> wrote:
--
View this message in context: http://r.789695.n4.nabble.com/Using-cumsum-with-group-by-tp4650457p4650461.html
Sent from the R help mailing list archive at Nabble.com.
??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.