【发布时间】:2018-09-03 01:09:44
【问题描述】:
> df <- read.csv("C:\\Users\\Vikas Kumar Dwivedi\\Desktop\\Yahoo.csv")
> df
Date Open High Low Close Adj.Close Volume
1 01-03-2013 null null null null null null
2 01-04-2013 1569.180054 1597.569946 1536.030029 1597.569946 1597.569946 77098000000
3 01-05-2013 1597.550049 1687.180054 1581.280029 1630.73999 1630.73999 76447250000
> df$Date <- as.Date(df$Date, format("%m/%d/%Y"))
> df <- df[order(df$Date), ]
> df<- as.xts(df[, 2], order.by = df$Date)
Error in UseMethod("as.xts") :
no applicable method for 'as.xts' applied to an object of class "factor"
我无法将数据帧转换为 xts?你能帮帮我吗?
【问题讨论】:
-
请提供csv的前几行。
-
我支持 G. Grothendieck 的评论...以表格形式读取文本会导致与您必须使用的数据结构不同,因为代码在
as.Date上失败。