Rolling window slider::slide() with grouped data
问题 In the following example I try to compute the first coefficient from a linear model for time t = 1 until t. It's an expanding rolling window. It works well with ungrouped data, but when grouped by case, I get the error Error: Column coef1 must be length 10 (the group size) or one, not 30 . How can I handle grouped data? library(dplyr) library(slider) get_coef1 <- function(data) { coef1 <- lm(data = data, r1 ~ r2 + r3) %>% coef() %>% .["r2"] %>% unname() return(coef1) } data <- tibble(t = rep