I want to create an xts
object in R, which I then want to decompose to seasonal and trend.
> require(xts)
> require(lubridate)
> chico
For the frequency of the time series of type xts: By default xts has a daily frequency, So you don't need to include any frequency if it is daily:
ctr.xts <- xts(chicos[, 7], order.by = chicos[, 8])
The R function decompose() works only with objects of type ts. So, you may like to convert the xts object to ts by issuing the following lines:
attr(ctr.xts, 'frequency') <- 7 # Set the frequency of the xts object to weekly
periodicity(ctr.xts) # check periodicity: weekly
plot(decompose(as.ts(ctr.xts))) # Decompose after conversion to ts
Also, you may like to try different frequencies:
Hope this may help.