r语言 - 为什么我的数字变量有日期,我如何将整个东西转换为xts?



输出的头部看起来像这样;当我执行str(输出)时,它似乎是一个维度为1的数字,我似乎无法提取日期,显然xts(输出)没有日期就无法工作。

2018-01-02 2018-01-03 2018-01-04 2018-01-05 2018-01-08 2018-01-09 2018-01-10 
0.000   6511.339   6575.760   6584.575   6653.247   6676.615   6677.939   6662.670   

似乎你有一个命名向量:

# create the vector `vector` with your values
vector <- c(6511.339, 6575.760, 6584.575, 6653.247, 6676.615, 6677.939, 6662.670)
# check vector (not named now)
vector
# add names to vector
names(vector) <- c("2018-01-02", "2018-01-03", "2018-01-04", "2018-01-05",
"2018-01-08"," 2018-01-09", "2018-01-10")
# now check named vector
vector
# get the names of the vector
names(vector)
#output:
[1] "2018-01-02"  "2018-01-03"  "2018-01-04"  "2018-01-05"  "2018-01-08"  " 2018-01-09"
[7] "2018-01-10" 

最新更新