I am trying to create statistics for the cumulative goals of the season by a specific football player. I used the cut function to get the season from the dates of the game. I have data that matches this data file
df.raw <- data.frame(Game = 1:20, Goals=c(1,0,0,2,1,0,3,2,0,0,0,1,0,4,1,2,0,0,0,3), season = gl(4,5,labels = c("2001", "2002","2003", "2004")))
In real life, the number of games per season may not be constant
I want to get data that looks like
df.seasoned <- data.frame(Game = 1:20,seasonGame= rep(1:5), Goals=c(1,0,0,2,1,0,3,2,0,0,0,1,0,4,1,2,0,0,0,3), cumGoals = c(1,1,1,3,4,0,3,5,5,5,0,1,1,5,6,2,2,2,2,5), season = gl(4,5,labels = c("2001", "2002","2003", "2004")))
With goals summarized throughout the year and game number during the season