您遇到错误的原因是滚动数据子集的缺失值(NA) .
以数据(瑞士)为例:
dim(swiss)
# [1] 47 6
split_swiss
length(split_swiss)
# [1] 47 ## rolling subset produce 47 data.frames.
lapply(tail(split_swiss), head) # show the first 6 rows of the last 6 data.frames
[[1]]
Fertility Agriculture Examination Education Catholic Infant.Mortality
Neuchatel 64.4 17.6 35 32 16.92 23.0
Val de Ruz 77.6 37.6 15 7 4.97 20.0
ValdeTravers 67.6 18.7 25 7 8.65 19.5
V. De Geneve 35.0 1.2 37 53 42.34 18.0
Rive Droite 44.7 46.6 16 29 50.43 18.2
Rive Gauche 42.8 27.7 22 29 58.33 19.3
[[2]]
Fertility Agriculture Examination Education Catholic Infant.Mortality
Val de Ruz 77.6 37.6 15 7 4.97 20.0
ValdeTravers 67.6 18.7 25 7 8.65 19.5
V. De Geneve 35.0 1.2 37 53 42.34 18.0
Rive Droite 44.7 46.6 16 29 50.43 18.2
Riv