joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 71 forks source link

Should as.xts() create an index with the smallest resolution? #192

Open joshuaulrich opened 7 years ago

joshuaulrich commented 7 years ago

The as.xts() function currently returns an object with a POSIXct index, unless you specify otherwise via the dateFormat argument.

library(xts)
data(sample_matrix)
p <- as.xts(sample_matrix)
d <- as.xts(sample_matrix, dateFormat = "Date")

This can be confusing to users who expect to be able to do things like this without issue:

d <- head(as.xts(sample_matrix, dateFormat = "Date"))
r <- as.xts(t(apply(d, 1, rank)))
merge(r, d)
merge(d, r)

It doesn't seem completely unreasonable for as.xts to return an object with a Date index, so that r could be easily merged with d. (The fact that merge(r, d) and merge(d, r) return different results is discussed in #191.)