I have the following data set (code requires the forecast
package for the tslm
call.
x <- rnorm(11, mean = 534, sd = 79)
y <- rnorm(9, mean = 800, sd = 56)
p <- list(x, y)
tsl <- list(); ts_trend <- list()
for(i in seq_along(p)) {
tsl[[i]] <- ts(p[[i]], start = c(2018, 1), frequency = 52)
}
for(i in seq_along(tsl)) {
ts_trend[[i]] <- tslm(tsl[[i]] ~ trend)
}
When I run it, I get the error
Error in tsl[[i]] : subscript out of bounds
The subscript, to my knowledge, is clearly not out of bounds. I use the same reference in the prior loop, with no error.
I have no idea how to fix this. What am I missing?