繁体   English   中英

为什么我的数字变量有日期以及如何将整个变量转换为 xts?

[英]Why does my numeric variable have dates and how do I convert the whole thing to xts?

我的output的头像是这样的; 当我执行 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" 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM