Hello, First of all, I'm new to R and I don't have anyone who already knows the language to ask for tips, so please excuse my ignorance. I'm trying to download data direct from the Federal Reserve statistics website and graph it, using the following: #This downloads the data from the Fed website download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat") #This reads that data into a table data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T) #This is attempting to get R to read the date column, which is in "mm/dd/yyyy" format #I have restricted it to the first 50 data points (to keep it simple) date_vec = as.Date(data_download[1:50,1],"%m/%d/%y") #This reads the values again for just the first 50 data points eurodollar_vec = data_download[1:50,2] #This plots the date and data values. plot(date_vec,eurodollar_vec) A few issues with the output from this: 1) The date_vec data ends up looking like this "2019-01-04" - for some reason all year 2019, irrespective of the actual year (e.g. 1971, 1972). Any suggestions as to where I am going wrong? 2) The chart ends up as a scatter diagram, not surprisingly. I initially tried to use the ts.plot() function but when I did, I found that it doesn't use the date column in the data as the x axis. Is there a way of creating a time series that uses the date column, or alternatively, how would I turn these two columns (date & value) into a line graph? 3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis shows as being about 430-670. There also seems to be a line of points across the top which are all of the same value - as though anything above about 670 gets charted as 670. I'm sorry for this being a "what am I doing wrong" post, but I have looked through the manuals without success, and I am new enough to R that I don't have a feel for ways round these sorts of problems. Any suggestions would be greatly appreciated. Thanks. -- View this message in context: http://www.nabble.com/Getting-started%2C-tp22719735p22719735.html Sent from the R help mailing list archive at Nabble.com.
In answer to your first question, your statement should be: date_vec = as.Date(data_download[1:50,1],"%m/%d/%Y") Notice the capital "Y"; lower case says the year is only 2 digits, so you were pickup up the '19' from the date. Use 'plot(..., type='l')' for a line plot. Your data is being read in as factors:> str(data_download)'data.frame': 9972 obs. of 2 variables: $ DATE: Factor w/ 9972 levels "01/01/1973","01/01/1974",..: 84 112 140 167 195 279 307 335 362 390 ... $ EDM1: Factor w/ 673 levels " 0.70"," 0.75",..: 599 597 593 594 591 586 583 571 574 586 ... You need to convert EDM1 to numeric data_download$EDM1 <- as.numeric(as.character(data_download$EDM1)) and then your data will plot as you like. On Thu, Mar 26, 2009 at 6:58 AM, gug <guygreen at netvigator.com> wrote:> > Hello, > > First of all, I'm new to R and I don't have anyone who already knows the > language to ask for tips, so please excuse my ignorance. > > I'm trying to download data direct from the Federal Reserve statistics > website and graph it, using the following: > > ? ? ? ?#This downloads the data from the Fed website > download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat") > > ? ? ? ?#This reads that data into a table > data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T) > > ? ? ? ?#This is attempting to get R to read the date column, which is in > "mm/dd/yyyy" format > ? ? ? ?#I have restricted it to the first 50 data points (to keep it simple) > date_vec = as.Date(data_download[1:50,1],"%m/%d/%y") > > ? ? ? ?#This reads the values again for just the first 50 data points > eurodollar_vec = data_download[1:50,2] > > ? ? ? ?#This plots the date and data values. > plot(date_vec,eurodollar_vec) > > > A few issues with the output from this: > > 1) The date_vec data ends up looking like this "2019-01-04" - for some > reason all year 2019, irrespective of the actual year (e.g. 1971, 1972). > Any suggestions as to where I am going wrong? > > 2) The chart ends up as a scatter diagram, not surprisingly. ?I initially > tried to use the ts.plot() function but when I did, I found that it doesn't > use the date column in the data as the x axis. ?Is there a way of creating a > time series that uses the date column, or alternatively, how would I turn > these two columns (date & value) into a line graph? > > 3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis > shows as being about 430-670. ?There also seems to be a line of points > across the top which are all of the same value - as though anything above > about 670 gets charted as 670. > > > I'm sorry for this being a "what am I doing wrong" post, but I have looked > through the manuals without success, and I am new enough to R that I don't > have a feel for ways round these sorts of problems. ?Any suggestions would > be greatly appreciated. ?Thanks. > -- > View this message in context: http://www.nabble.com/Getting-started%2C-tp22719735p22719735.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Try this: library(zoo) library(chron) my.url <- "http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt" z <- read.zoo(my.url, skip = 8, header = TRUE, sep = ",", na.strings = "ND", strip.white = TRUE, FUN = as.chron) plot(z[1:50,]) # or to plot with NAs interpolated plot(na.approx(z[1:50,])) See the three zoo vignettes: vignette(package = "zoo") vignette("zoo") # etc. and for more on dates see R News 4/1. On Thu, Mar 26, 2009 at 6:58 AM, gug <guygreen at netvigator.com> wrote:> > Hello, > > First of all, I'm new to R and I don't have anyone who already knows the > language to ask for tips, so please excuse my ignorance. > > I'm trying to download data direct from the Federal Reserve statistics > website and graph it, using the following: > > ? ? ? ?#This downloads the data from the Fed website > download.file("http://www.federalreserve.gov/releases/h15/data/Business_day/H15_ED_M1.txt","Eurodollar_deposits1M.dat") > > ? ? ? ?#This reads that data into a table > data_download=read.table("Eurodollar_deposits1M.dat",skip=8,sep=",",head=T) > > ? ? ? ?#This is attempting to get R to read the date column, which is in > "mm/dd/yyyy" format > ? ? ? ?#I have restricted it to the first 50 data points (to keep it simple) > date_vec = as.Date(data_download[1:50,1],"%m/%d/%y") > > ? ? ? ?#This reads the values again for just the first 50 data points > eurodollar_vec = data_download[1:50,2] > > ? ? ? ?#This plots the date and data values. > plot(date_vec,eurodollar_vec) > > > A few issues with the output from this: > > 1) The date_vec data ends up looking like this "2019-01-04" - for some > reason all year 2019, irrespective of the actual year (e.g. 1971, 1972). > Any suggestions as to where I am going wrong? > > 2) The chart ends up as a scatter diagram, not surprisingly. ?I initially > tried to use the ts.plot() function but when I did, I found that it doesn't > use the date column in the data as the x axis. ?Is there a way of creating a > time series that uses the date column, or alternatively, how would I turn > these two columns (date & value) into a line graph? > > 3) The y-axis output should be from about 4.5 to about 8.5, but the y-axis > shows as being about 430-670. ?There also seems to be a line of points > across the top which are all of the same value - as though anything above > about 670 gets charted as 670. > > > I'm sorry for this being a "what am I doing wrong" post, but I have looked > through the manuals without success, and I am new enough to R that I don't > have a feel for ways round these sorts of problems. ?Any suggestions would > be greatly appreciated. ?Thanks. > -- > View this message in context: http://www.nabble.com/Getting-started%2C-tp22719735p22719735.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >