Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error in mutate_impl(.data, dots) : Evaluation error: k <= n is not TRUE
- i = 3
- QBrollavgDT <- data.table(rankDT)
- QBrollavgDT <- QBrollavgDT[, c("Player_Name", "Season", "Week", "FDP")]
- #QBrollavgDT <- subset(QBrollavgDT, Player_Name == "K.Collins") <- This works
- #QBrollavgDT <- QBrollavgDT[c(381,759,1140,1510,1888,2264.2641), ] <- these are the rows that thorw the error
- #begin calculating the rolling average and eliminating players with < i games played
- QBrollavgDT <- setDT(QBrollavgDT)[, if (.N >= i) .SD, by = Player_Name] #this eliminates all players with < i games played
- QBrollavgDT <- QBrollavgDT %>% #this is the code that puts the rolling average on and names the column RollAvg
- arrange(Player_Name, Season, Week) %>%
- group_by(Player_Name, Season) %>%
- mutate(RollAvg = zoo::rollapply(FDP, i, mean, by = 1, align = "right", fill = NA))
Add Comment
Please, Sign In to add comment