This is my data:
ID<-rep(1:5, length.out=15 )
b<-cumsum(1:10)
c<-cumsum(1:10)*2
bc<-c(b,c)
e<-cbind(ID,bc)
e<-as.data.frame(e)
e$ID<-as.factor(e$ID)
I would like a third column that contains values that cumulative sums were derived from. This is the expected outcome. I know I need to group by ID, but no idea which function to use to do what I want.
f<-e %>% group_by(ID) %>% mutate(num=
ID bc num
1 1 1 1
2 2 3 2
3 3 6 3
4 4 10 4
5 5 15 5
6 1 2 2