I have the following code and I would like to be able to just change 'x' and 'stat' and run the whole code. At the moment I have to manualy change 'pts' in the 5th line in the rollapply function. If I change 'pts' to 'stat' there is an error. Thanks for any help!
x = 5
stat = 'pts'
game_stats[,paste0('l',x,'g_', stat):=0]
game_stats[,paste0('l',x,'g_', stat):=NA]
game_stats[,paste0('l',x,'g_', stat):=rollapply(pts, list(-(1:x)), mean, fill=NA, align='right'),
by=team]