Just try it. We show two equivalent ways to define R squared in this context:
library(zoo)
set.seed(123)
n <- 4680
w <- 60
x <- rnorm(4680)
r2 <- function(x) summary(lm(x ~ seq_along(x)))$r.squared
# r2 <- function(x) cor(x, seq_along(x))^2 # this is equivalent
mean(rollapplyr(x, w, r2))
## [1] 0.4992133
r2(x)
## [1] 0.0001151601
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…