Created
December 27, 2012 07:57
-
-
Save yanping/4386439 to your computer and use it in GitHub Desktop.
Read Exchange Rate from the Federal Reserve Bank of New York
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read Exchange Rate from the Federal Reserve Bank of New York | |
# website is http://www.federalreserve.gov/releases/h10/hist/ | |
# For example read the exchange rate of Australian Dollar | |
require(RCurl) | |
require(XML) | |
require(stringr) | |
setwd("F:/") | |
# website of Australian Dollar, you can change the URL for other currency | |
url = "http://www.federalreserve.gov/releases/h10/hist/dat00_al.htm" | |
doc = getURL(url) | |
txt = htmlParse(doc) | |
date <- sapply(getNodeSet(txt, "//table[@class='statistics']//th[@id='r1']"), xmlValue) | |
rate <- sapply(getNodeSet(txt, "//table[@class='statistics']//td"), xmlValue) | |
options(warn = -1) | |
rate <- as.numeric(str_trim(rate)) | |
options(warn = 1) | |
data <- data.frame(date,rate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment