E.D.
E.D.

Reputation: 329

Remove time from XTS

I am trying to compare different timeseries, by day.

Currently a typical XTS object looks like:

> vwap.crs
                    QUANTITY QUANTITY.1
2014-03-03 13:00:00 3423.500     200000
2014-03-04 17:00:00 3459.941    4010106
2014-03-05 16:00:00 3510.794    1971234
2014-03-06 17:00:00 3510.582     185822

now, i can strip the time out of the index as follows:

> round(index(vwap.crs),"day")
[1] "2014-03-04" "2014-03-05" "2014-03-06" "2014-03-07"

My question is, how do I replace the existing index in variable vwap.crs, with the rounded output above?

EDIT: to.daily fixed it

Upvotes: 4

Views: 5095

Answers (1)

GSee
GSee

Reputation: 49830

This should do it

indexClass(vwap.crs) <- "Date"

Also, take a look at the code in xts:::.drop.time


You could also do it the way you're trying to do it if you use index<-

index(vwap.crs) <- round(index(vwap.crs),"day")

Upvotes: 8

Related Questions