I'm writing a function which forecasts some user-inputted data, by fitting an AR model. Outside the function, the code may look like
dat <- c(1,1.1,1,1.2)
print(forecast(ar(dat)))
This runs just fine.
If this is now put inside a function, like:
func <- function(data_input)
{
temp <- forecast(ar(data_input))
print(temp)
}
func(dat)
I get this error:
Error in ts(x) : 'ts' object must have one or more observations
Please could someone explain what's going on here?