For the first (left) set of records I have generated cumulative sum of 'values' column for each ID
xyz = data.frame(
"ID"=c("A","A","A","A","A","B","B","B","B","B","B","B","C","C","C","C"),"Value"=as.integer(rnorm(16,mean = 5,sd = 5)))
xyz1=xyz
A=cumsum(xyz1$Value[xyz1$ID=="A"] )
B = cumsum(xyz1$Value[xyz1$ID=="B"])
C = cumsum(xyz1$Value[xyz1$ID=="C"])
abc=vector(length=nrow(xyz))
abc[1:5]=A
abc[6:12]=B
abc[13:16]=C
xyz1=cbind(xyz,abc)
# How to repeat this for large no. of ID's like in 1000's
But, for 2nd set of records (on the right) I have to make cumulative sum of three records at a time. Like in table column (Column_to_make) the last record of A has sum of last 3 values (7+7+8)==22
the above record is sum of (7+8+4)==19. and so on...…….
How can I automate the method of cumsum as described above for large number of ID's like in 1000's.
Thanking You for your time.