Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
gold prices from measuring worth in r
#R example of using prices from
#if you use and like their data, I strongly encourage donating to the cause
#ugly way to specify url for prices you would like
#shiny would provide a very nice interface once I get motivated
#this particular example will download prices from 1718 to 2013 for New York and London market
#redundant since London market dataset switched to New York in 1950
url = paste("",
"year_source=1791&", #1257, 1786, 1791, 1687, or 1718
"year_result=",format(Sys.Date(),"%Y"),"&", #any year to current except for 1945 for British official
#set on for the following data sources
#time range set above must fall within the years specified
#can specify multiple sources
"British=&", #British official price (1257-1945)
"us=&", #U.S. official price (1786-Present)
"newyork=on&", #New York market price (1791-Present)
"goldsilver=&", #Gold/silver price ratio (1687-Present)
"london=on", #London market price (1718-Present) switches to New York 1950
goldprices <- apply(read.csv(url,stringsAsFactors=FALSE),MARGIN=2,FUN=as.numeric)
#get in xts format for easier time-series handling
goldprices.xts <- na.omit(xts(goldprices[,2:ncol(goldprices)], = as.Date(paste(goldprices[,1],"-12-31",sep="")))) #set each year to end of year 12/31/Year
yscale.components = yscale.components.log10ticks,
main="Gold Prices from MeasuringWorth (")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment