xts 包,to.weekly():如何保留初始列名

xts package, to.weekly(): How to keep initial column names

我有一些数据想用 xts 包更改为每周一次,除了列名以不希望的方式更改外,一切正常。

如你所见...

> head(x)
           Open High  Low Close Volume (BTC) Volume (Currency) Weighted Price
2011-09-13 5.80 6.00 5.65  5.97     58.37138          346.0974       5.929231
2011-09-14 5.58 5.72 5.52  5.53     61.14598          341.8548       5.590798
2011-09-15 5.12 5.24 5.00  5.13     80.14080          408.2590       5.094272
2011-09-16 4.82 4.87 4.80  4.85     39.91401          193.7631       4.854515
2011-09-17 4.87 4.87 4.87  4.87      0.30000            1.4610       4.870000
2011-09-18 4.87 4.92 4.81  4.92    119.81280          579.8431       4.839576
> x.weekly  <- to.weekly(x)
> head(x.weekly)
           x.Open x.High x.Low x.Close x.Volume
2011-09-18   5.80   6.00  4.80    4.90 379.6850
2011-09-25   4.92   6.06  4.80    4.80 313.7540
2011-10-02   4.85   4.92  0.00    4.87 184.9483
2011-10-09   4.86   6.25  3.89    4.51 721.2252
2011-10-16   3.98   4.10  0.00    3.92 374.4428
2011-10-23   0.00   2.99  0.00    2.92 167.9757

有什么快速的方法可以分别保留初始列名吗?我试过 to.weekly(x, names = "") 但这给出了以下名称 .Open, .High

to.weekly 调用中设置 name = NULL

require(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
head(to.weekly(x))
#              x.Open   x.High    x.Low  x.Close
# 2007-01-07 50.03978 50.42188 49.95041 49.99185
# 2007-01-14 50.03555 50.62395 49.80454 50.60145
# 2007-01-21 50.61724 50.77336 50.02142 50.42090
# 2007-01-28 50.36008 50.43875 49.87468 49.88096
# 2007-02-04 49.85624 50.55509 49.76308 50.55509
# 2007-02-11 50.52389 50.91776 50.45977 50.91160
head(to.weekly(x, name=NULL))
#                Open     High      Low    Close
# 2007-01-07 50.03978 50.42188 49.95041 49.99185
# 2007-01-14 50.03555 50.62395 49.80454 50.60145
# 2007-01-21 50.61724 50.77336 50.02142 50.42090
# 2007-01-28 50.36008 50.43875 49.87468 49.88096
# 2007-02-04 49.85624 50.55509 49.76308 50.55509
# 2007-02-11 50.52389 50.91776 50.45977 50.91160