xts对象列表中的rbind.xts

问题描述 投票:0回答:1

我有一个xts对象的列表,这些对象具有共同的索引名和列名。

我想按索引查找并平均各列:

dts = seq.POSIXt(from = Sys.time() - days(2), to = Sys.time(), by = 'day')
x1 = xts(x = 1:3, order.by = dts)
names(x1) = 'a'
x2 = xts(x = 2:4, order.by = dts)
names(x2) = 'a'

x = rbind.xts(x1, x2)  
aggregate(x, index(x), 'mean')

这对于我想要的来说效果很好,问题在于xts对象存储在列表中,而不是作为单独的对象存储。

如果我尝试

rbind.xts(list(x1, x2))

他们不加入:

[[1]]
                    a
2020-04-04 15:17:42 1
2020-04-05 15:17:42 2
2020-04-06 15:17:42 3

[[2]]
                    a
2020-04-04 15:17:42 2
2020-04-05 15:17:42 3
2020-04-06 15:17:42 4

如何从列表中搜索?

r xts zoo
1个回答
0
投票

我们可以使用do.call

do.call(rbind, list(x1, x2))
© www.soinside.com 2019 - 2024. All rights reserved.