, R , HomeTeam, Date:
my.data <- read.csv(text = '
Div, Date, HomeTeam, AwayTeam, FTHG, FTAG
D1, 14/08/15, Bayern Munich, Hamburg, 5, 0
D1, 15/08/15, Bayern Munich, Hertha, 0, 1
D1, 16/08/15, Darmstadt, Hannover, 2, 2
D1, 17/08/15, Darmstadt, Ingolstadt, 4, 0
D1, 18/08/15, Darmstadt, Hoffenheim, 2, 1
D1, 19/08/15, Mainz, Ingolstadt, 0, 1
', header = TRUE, stringsAsFactors = FALSE, strip.white = TRUE)
my.data <- my.data[with(my.data, order(HomeTeam, Date)), ]
my.data
my.means <- aggregate(my.data$FTHG, by=list(my.data$HomeTeam),
FUN = {function(x) cumsum(x)/seq(from=1, to=length(x)) })
my.data$my.cum.means <- c(unlist(my.means[2]))
my.data