我有一个索引和列名相同的xts对象列表。
我希望按索引进行rbind,并对列进行平均:
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如何从列表中rbind?
发布于 2020-04-07 06:20:28
我们可以使用do.call
do.call(rbind.xts, list(x1, x2))
# a
#2020-04-04 18:19:33 1
#2020-04-04 18:19:33 2
#2020-04-05 18:19:33 2
#2020-04-05 18:19:33 3
#2020-04-06 18:19:33 3
#2020-04-06 18:19:33 4或者逐个提取list元素并应用rbind
lst1 <- list(x1, x2)
rbind.xts(lst1[[1]], lst1[[2]])https://stackoverflow.com/questions/61069847
复制相似问题