Следующее странное поведение происходит с xts
объектом:
library(xts)
x1 <- structure(c(1, 2, 3), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC",
tzone = "UTC", index = structure(c(1419897600, 1421432228.57143, 1423915200),
tzone = "UTC", tclass = "Date"),
class = c("xts", "zoo"), .Dim = c(3L, 1L))
y1 <- xts(3:1, index(x1))
x1 - y1
e1
2014-12-30 -2
Вычитание двух серий завершается неудачно: возвращается только первый компонент.
Я подозреваю, что это связано с индексом x1
, который по определению является индексом y1
.
Однако, похоже, это решает проблему:
index(x1) <- index(x1)
x1 - y1
[,1]
2014-12-30 -2
2015-01-16 0
2015-02-14 2
Может кто-нибудь объяснить это поведение.
Для меня это похоже на ошибку.
Вот вывод sessionInfo()
.
R version 3.5.1 (2018-07-02)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252
[3] LC_MONETARY=German_Austria.1252 LC_NUMERIC=C
[5] LC_TIME=German_Austria.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xts_0.11-0 zoo_1.8-3
loaded via a namespace (and not attached):
[1] compiler_3.5.1 tools_3.5.1 grid_3.5.1 lattice_0.20-35