I have the following data frame in R
called df
:
id<-c(1,1,1,1,2,3,3,3,3)
day<-c(1,2,4,5,2,2,3,6,8)
payment<-c(5,10,3,30,23,40,20,10,50)
df<-data.frame(id,day,payment)
id day payment
1 1 5
1 2 10
1 4 3
1 5 30
2 2 23
3 2 40
3 3 20
3 6 10
3 8 50
what I'm trying to do is creating a new variable called soFarMax
, it represents the maximum payment that the associated id
has made until that day:
id day payment SoFarMax
1 1 5 5
1 2 10 10
1 4 3 10
1 5 30 30
2 2 23 23
3 2 40 40
3 3 20 40
3 6 10 40
3 8 50 50
Would appreciate your help with this.