Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Last active January 4, 2016 17:59
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 timelyportfolio/8657865 to your computer and use it in GitHub Desktop.
Save timelyportfolio/8657865 to your computer and use it in GitHub Desktop.
Get Currency Codes for St. Louis Fed FRED with R
#ugly but works
#should verify that I do not belong on the R Core Team
getFredCurrencies <- function (){
require(XML)
doc <- htmlParse("http://research.stlouisfed.org/fred2/categories/94")
currencyList <- xpathSApply(
doc,
path = '//*[contains(concat( " ", @class, " " ), concat( " ", "series-title", " " ))]'
)
currencies <- do.call(rbind,
lapply(currencyList,function(curr){
curr.df = data.frame(
xmlGetAttr(curr,"href"),
xmlValue(curr),
stringsAsFactors=F
)
curr.df[,1] = strsplit(curr.df[,1],"[/ || \\?]")[[1]][4]
colnames(curr.df) <- c("code","title")
return(curr.df)
})
)
return(currencies)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment