Last active
January 4, 2016 17:59
-
-
Save timelyportfolio/8657865 to your computer and use it in GitHub Desktop.
Get Currency Codes for St. Louis Fed FRED with R
This file contains 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
#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