I am either misunderstanding the docs or having a problem with the drop.time=TRUE
parameter in to.weekly()
. For a simple example, add a time component onto some sample daily data and roll it up to weekly:
library(xts)
data(sample_matrix)
d <- as.xts(sample_matrix)
index(d) <- index(d)+50
w1 <- to.weekly(d, drop.time=TRUE)
head(w1,1)
d.Open d.High d.Low d.Close
2007-01-07 00:00:50 50.03978 50.42188 49.95041 49.99185
w2 <- to.weekly(d, drop.time=FALSE)
head(w2,1)
d.Open d.High d.Low d.Close
2007-01-07 00:00:50 50.03978 50.42188 49.95041 49.99185
The docs say:
Setting
drop.time
to TRUE (the default) will convert a series that includes a time component into one with just a date index, as the time index is often of little value in lower frequency series.
This question mentions that drop.time
depends upon indexClass(d)[1] == 'POSIXt'
but that appears not to help:
indexClass(d)
[1] "POSIXct" "POSIXt"
indexClass(d) <- c('POSIXt', 'POSIXct')
w3 <- to.weekly(d, drop.time=TRUE, name=NULL)
head(w3,1)
Open High Low Close
2007-01-07 00:00:50 50.03978 50.42188 49.95041 49.99185
I'm sure I can just truncate off the time component, but am curious what I'm doing wrong.