Edit: I could reproduce the issue with xts 0.9-3. It has been fixed in xts 0.9-5. You need to update xts.
I believe this could be considered a bug.
head(x)
# JJ
#2013-08-23 14:12:19 100.02352
#2013-08-23 14:12:20 99.99044
#2013-08-23 14:12:21 99.95928
#2013-08-23 14:12:22 99.72914
#2013-08-23 14:12:23 99.71210
#2013-08-23 14:12:24 99.72609
methods(na.approx)
#[1] na.approx.default na.approx.ts* na.approx.zoo* na.approx.zooreg*
So, there is no xts method. Since
class(x)
#[1] "xts" "zoo"
na.approx.zoo
is dispatched. Inside that function essentially this happens:
index(x) <- index(x)
head(x)
# JJ
#2013-08-23 21:12:19 100.02352
#2013-08-23 21:12:20 99.99044
#2013-08-23 21:12:21 99.95928
#2013-08-23 21:12:22 99.72914
#2013-08-23 21:12:23 99.71210
#2013-08-23 21:12:24 99.72609
Note that index<-.xts
exists and is used here. Unfortunately, contrary to index<-.zoo
, it doesn't preserve the time zone (of the index).
So, you could use y <- na.approx(as.zoo(x))
to avoid the issue.