このページ(http://cfe.cboe.com/Products/historicalVIX.aspx)のすべてのCSVファイルをダウンロードして、VIX先物の過去の価格を取得しようとしています。これを行うために使用しているコードは次のとおりです。
library(XML)
#Extract all links for url
url <- "http://cfe.cboe.com/Products/historicalVIX.aspx"
doc <- htmlParse(url)
links <- xpathSApply(doc, "//a/@href")
free(doc)
#Filter out URLs ending with csv and complete the link.
links <- links[substr(links, nchar(links) - 2, nchar(links)) == "csv"]
links <- paste("http://cfe.cboe.com", links, sep="")
#Peform read.csv on each url in links, skipping the first two URLs as they are not relevant.
c <- lapply(links[-(1:2)], read.csv, header = TRUE)
エラーが発生します:
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
more columns than column names
さらに調べてみると、これは一部のCSVファイルの形式が異なるためであることがわかりました。URLlinks[9]
を手動でロードすると、最初の行に次の免責事項があることがわかります。
CFE data is compiled for the .......use of CFE data is subject to the Terms and Conditions of CBOE's Websites.
他のほとんどのファイル(例links[8]
とlinks[10]
)は問題ないので、これはランダムに挿入されているようです。これを処理するために実行できるRマジックはありますか?
ありがとうございました。