I have various financial data that I am trying to merge into an xts
object so I can perform multiple statistical analyses. I am having difficulty, however, with dates when moving from the original data to a zoo
object to an xts
object.
For instance, I read in some hedge fund return data, change the report date variable using the ymd
function from the lubridate
package, create a zoo
object, then just as a check create a timeSeries object. All seems to be OK, but I continue to get an error when I attempt to create the xts
object, as shown below:
hfIndexes$ReportDt <- ymd(hfIndexes$ReportDt)
hfIndexesZoo <- zoo(hfIndexes,order.by="ReportDt")
hfIndexesTimeSeries <- as.timeSeries(hfIndexesZoo)
hfIndexesXTS <- as.xts(hfIndexesZoo)
Error in xts(coredata(x), order.by = order.by, frequency = frequency, :
order.by requires an appropriate time-based object
What do I need to do to ensure that I have the correct time-based object to create the desired xts
object?