# xts object to ts object / seasonal dummies for xts

I am trying to use a function from the forecast package, seasonaldummy(), which requires a time series object as input, but I have an xts object, call it x. So first, is it correct that xts objects can not be directly passed to functions that require a ts object?

I then tried to coerce it to a ts object. I tried this by as.ts(x). The function still produces an error.

I looked at the xts vignette, and in particular the reclass function, but all I could understand from that was how to coerce non xts objects to xts. It appears I have to do the opposite, and that as.ts(x) does not work.

I have put a MWE below, where the last two lines generate an error.

> a = rnorm(20)
> dt = seq(as.POSIXct("2010-03-24"),by="days",len=20)
> library(xts)
> a = xts(a,dt)
> library(forecast)
> seasonaldummy(a)

Error in seasonaldummy(a) : Not a time series

> seasonaldummy(as.ts(a))

Error in seasonaldummy(as.ts(a)) : subscript out of bounds

-

To use seasonal dummy variables, the period of seasonality must be an integer. When you convert a to a time series using as.ts(a), the period is set to 1/86400 (seconds in a day). So if you want to use seasonal dummy variables you will have to specify what the most appropriate period is first. For example, if you want to use a day-of-week seasonality, use
seasonaldummy(ts(a,f=7))