I am downloading time series data from FRED. I have a working download, but I
do not want to write out the download for all 50 states likes this:
 IDRGSP <-
read.table('http://research.stlouisfed.org/fred2/data/IDRGSP.txt', skip=11,
header=TRUE)
IDRGSP$DATE <- as.Date(IDRGSP$DATE, '%Y-%m-%d')
IDRGSP$SERIES <- 'IDRGSP'
IDRGSP$DESC <-  "Real Total Gross Domestic Product by State for Idaho, Mil.
of, A, NSA, 2012-06-05"

WYRGSP <- read.table('http://research.stlouisfed.org/fred2/data/WYRGSP.txt',
skip=11, header=TRUE)
WYRGSP$DATE <- as.Date(WYRGSP$DATE, '%Y-%m-%d')
WYRGSP$SERIES <- 'WYRGSP'
WYRGSP$DESC <-  "Real Total Gross Domestic Product by State for Wyoming,
Mil. of, A, NSA, 2012-06-05"
RGSP <- rbind(IDRGSP, WYRGSP)

I want to loop but I can not get the paste to work correctly. I am trying
this:  Can someone help me figure out the loop so I can build a table for
all 50 states.
ab <- c(state.abb)
base <- "'http://research.stlouisfed.org/fred2/data/";
type <- "RGSP.txt', skip=11, header=TRUE";

tmp <- NULL;
for (a in ab) {
  url <- paste(base, a, type, sep="");

if (is.null(tmp))
    tmp <- read.table(url)
  else tmp <- rbind(tmp, read.table(url))
}
tmp

thanks for your help




--
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-R-loop-for-URL-download-from-FRED-to-create-US-time-series-tp4669209.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to