I have a CSV file with the format
ref_date;wings;airfoil;turbines
2015-03-31;123,22;22,77;99,0
2015-04-30;123,22;28,77;99,0
2015-05-31;123,22;22,177;02,0
2015-06-30;56,288;22,77;99,0
and I want to use the forecast
package to predict the next values of this time series. The forecast
package only accepts a ts
object, but so far all my attempts to create one failed. I tried to
1) Use zoo package
df = read.zoo(data_file, sep=';', dec=',', format="%Y-%m-%d", header=T)
but the data is truncated at the decimal point.
2) Use the zoo package with xts
df = read.zoo(datafile, sep=';', dec=',', format="%Y-%m-%d", header=T)
df_ts = ts(df)
The dates are nowhere to be seen, the index is just a sequence of numbers, like
1 123.22 22.77 99
3) Use read.csv and ts
df = read.zoo(datafile, sep=';', dec=',', format="%Y-%m-%d", header=T)
df_ts = ts(df)
4) Try using xts
df = read.csv(data_file, sep=';', header=T, dec=',')
tt = as.xts(df[,-1],order.by = as.Date(as.character(df[,1]), format = "%Y-%m-%d"))
forecast(tt)
Error in `tsp<-`(`*tmp*`, value = tsp.y) :
invalid time series parameters specified
the result looses all information about the date, including the ref_date column, and now the forecast package gives nonsense as result.
What is the correct approach to create the object that the forecast
library is waiting and can generate a forecast, maintaining the dates, including in the plots?
zoo
did you use? I tested withzoo_1.7-14
. - MrFlickdf
might suggests. - G. Grothendieck