【发布时间】:2016-02-03 15:29:27
【问题描述】:
我想从ECB website 中提取汇率来转换我的本地货币数据。但是,我在使用 xpath 时遇到了很多困难(尽管 this 帮了我很多)。
library(XML)
fileURL <- "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?93aad09b8f8b7bdb69cd1574b5b2665f"
download.file(fileURL, destfile=tf <- tempfile(fileext=".xml"))
xml_file <- xmlParse(tf)
xml_data <- xmlRoot(xml_file)
currency <- xml_data[["number(//Cube/@currency)"]]
rate <- xml_data[["number(//Cube/@rate)"]]
然后我只想创建简单的数据框:
df <- data.frame(currency, rate)
【问题讨论】: