2014-04-21 88 views
-2

X = read.csv(file.choose())中的R quantmod錯誤

頭(X)

Date  Open High Low Close Volume 
1 2013/1/2 13257 13289 13162 13194 168353 
2 2013/1/3 13195 13198 13055 13055 242457 
3 2013/1/4 13050 13100 13005 13079 256215 
4 2013/1/7 13085 13128 13025 13126 228488 
5 2013/1/8 13136 13148 13064 13088 227064 
6 2013/1/9 13091 13104 13044 13072 219862 

庫(quantmod)

BARCHART(X)

在try.xts錯誤(x,error =「chartSeries需要一個非法對象」): chartSeries需要一個非法對象

+0

你能解釋一下更清楚你想要達到什麼樣的? – Jaap

+1

將'x'轉換爲xts或轉換爲與'as.xts'一起使用的data.frame。 –

+0

step1.write .zoo step2。 as.xts – user3556887

回答

1

你可以在一行中完成。假設您正在加載的文件在您的「數據」目錄中名爲「spy.csv」,並保存SP500 OHLC數據。

spy <-as.xts(read.zoo("~/data/spy.csv",header=TRUE,sep=",",colClasses = c("Date", rep("numeric",4)))) 

barChart(SPY) 

會顯示您的圖表中的所有它的榮耀:-)

0

如果我們假設該文件的名稱是全球植物保護戰略,通過加載解決方案,我們會得到!

Error in file(file, "rt") : cannot open the connection 

另外:警告消息:

In file(file, "rt") : 
cannot open file 'GSPC.csv': No such file or directory ====> my file is existed !!!