'Error in forecast and accuracy function in R

I want to train an arima model and want some forecast.

So I am doing this:

arima<-function(train, val, column)
{
model = auto.arima(train[[column]], trace=TRUE, stepwise=FALSE, approximation = FALSE)
acc=accuracy(model)
pred=forecast(model, length(val[[column]]))
acc=accuracy(pred, val[[column]])
return(acc)
}

Then I am getting this error:

Error in accuracy.default(pred, val[[column]]): First argument should be a forecast object or a time series.

According to me pred should be a forecast object.

pred right now :

$pred
Time Series:
Start=220
End=220
Frequency=1
[1] 2.72
$se
Time Series:
Start=220
End=220
Frequency=1
[1] 0.13

Please give me some advice I am stuck here...

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source