如何将XTS转换为包含索引列的data.frame?

时间:2018-10-03 17:42:57

标签: r dataframe xts quantmod

我从Quantmod中提取库存信息,它返回一个xts对象,其中的索引是每一行数据所对应的日期。如何将索引转换为列?我附上了数据框前6行的屏幕截图。

index column has dates

编辑:与How can I change XTS to data.frame and keep Index?不同,因为此问题来自认为数据存储在data.frame中的用户。对于不了解情况或新手的潜在有用问题。

1 个答案:

答案 0 :(得分:-1)

尝试下面的代码,它可用于数据帧,我不确定它如何处理ti

library(dplyr)
library(magrittr)

#assuming "df" is the variable name fo the data
df <- df %>%
    mutate(names = rownames(df))

#this should add a column named "names" which
#has the corresponding rownames. 
#df rownames should now return an index

新列可能是字符向量,而不是标准日期模式之一。

相关问题