为什么我的数字变量有日期以及如何将整个变量转换为 xts?
Why does my numeric variable have dates and how do I convert the whole thing to xts?
我输出的头部是这样的;当我执行 str(output) 时,它似乎是一个维度为 1 的数字,而且我似乎无法提取日期,显然 xts(output) 没有日期就无法工作。
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"
我输出的头部是这样的;当我执行 str(output) 时,它似乎是一个维度为 1 的数字,而且我似乎无法提取日期,显然 xts(output) 没有日期就无法工作。
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"