【发布时间】:2020-03-16 19:14:51
【问题描述】:
我想以可以用作 3d 数组的方式访问 xts 对象列表。
这是示例数据。由于这只是一个示例,因此我在所有对象中保留了相同的数据。
data(sample_matrix)
sample.xts_1 <- as.xts(sample_matrix, descr='Object 1')
sample.xts_2 <- as.xts(sample_matrix, descr='Object 2')
sample.xts_3 <- as.xts(sample_matrix, descr='Object 3')
data_list = list(a = sample.xts_1, b = sample.xts_2, c = sample.xts_3)
这个数据看起来像这样 -
$a
Open High Low Close
2007-01-02 50.0 50.1 50.0 50.1
2007-01-03 50.2 50.4 50.2 50.4
$b
Open High Low Close
2007-01-02 50.0 50.1 50.0 50.1
2007-01-03 50.2 50.4 50.2 50.4
$c
Open High Low Close
2007-01-02 50.0 50.1 50.0 50.1
2007-01-03 50.2 50.4 50.2 50.4
有没有一种简单的方法可以按以下方式访问这些列表元素?
$open
a b c
2007-01-02 50.0 50.0 50.0
2007-01-03 50.2 50.2 50.2
2007-01-04 50.4 50.4 50.4
2007-01-05 50.4 50.4 50.4
2007-01-06 50.2 50.2 50.2
2007-01-07 50.1 50.1 50.1
2007-01-08 50.0 50.0 50.0
$high
a b c
2007-01-02 50.1 50.1 50.1
2007-01-03 50.4 50.4 50.4
2007-01-04 50.4 50.4 50.4
2007-01-05 50.4 50.4 50.4
2007-01-06 50.2 50.2 50.2
2007-01-07 50.2 50.2 50.2
2007-01-08 50.1 50.1 50.1
$low
a b c
2007-01-02 50.0 50.0 50.0
2007-01-03 50.2 50.2 50.2
2007-01-04 50.3 50.3 50.3
2007-01-05 50.2 50.2 50.2
2007-01-06 50.1 50.1 50.1
2007-01-07 50.0 50.0 50.0
2007-01-08 50.0 50.0 50.0
$close
a b c
2007-01-02 50.1 50.1 50.1
2007-01-03 50.4 50.4 50.4
2007-01-04 50.3 50.3 50.3
2007-01-05 50.3 50.3 50.3
2007-01-06 50.2 50.2 50.2
2007-01-07 50.0 50.0 50.0
2007-01-08 50.0 50.0 50.0
【问题讨论】: