簡體   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