我有一个数据框 games_h。这只是表格的一个片段,但它有很多球队,并按日期、球队、比赛编号排序。我正在尝试创建按团队分组的加权滚动平均值。我希望最近一场比赛的权重是两场以上之前的。因此权重将为 (Game_1 * 1+ Game_2 *2)/3 或权重等于 1,且比率相同,因此权重 = c(1-.667, .667)。
dput(games_h)
structure(list(GameId = c(16, 16, 37, 37, 57, 57), GameDate = structure(c(17905,
17905, 17916, 17916, 17926, 17926), class = "Date"), NeutralSite = c(0,
0, 0, 0, 0, 0), AwayTeam = c("Virginia Cavaliers", "Virginia Cavaliers",
"Florida State Seminoles", "Florida State Seminoles", "Syracuse Orange",
"Syracuse Orange"), HomeTeam = c("Boston College Eagles", "Boston College Eagles",
"Boston College Eagles", "Boston College Eagles", "Boston College Eagles",
"Boston College Eagles"), Team = c("Virginia Cavaliers", …Run Code Online (Sandbox Code Playgroud)