Skip to content

Instantly share code, notes, and snippets.

@yanping
Created December 27, 2012 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanping/4386439 to your computer and use it in GitHub Desktop.
Save yanping/4386439 to your computer and use it in GitHub Desktop.
Read Exchange Rate from the Federal Reserve Bank of New York
# 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