Hello, I am currently attempting to introduce R at my company and am trying to import time series data from a text file into R to graph. The format of the text file is in date, data (e.g., 20040929 3.361). My problem is that I do not know how to get R to recognize the first column as a business date series. Or at the very least, I am unable to find a function that will grap the second column (y-axis) against the date series (x-axis). If you could tell me how to graph this type of data, I would greatly appreciate it. Thank you. Regards, John DeAngelis
On Mon, 4 Oct 2004 09:00:46 -0400 John DeAngelis wrote:> > > > Hello, > > I am currently attempting to introduce R at my company and am trying > to import time series data from a text file into R to graph. The > format of the text file is in date, data (e.g., 20040929 3.361).You can read in such a file, e.g., via R> x <- read.table(file = "mydata.txt", colClasses = c("character", "numeric"))> My problem is that I do > not know how to get R to recognize the first column as a business date > series.You can do that via strptime(), e.g., R> strptime(x[,1], "%Y%m%d") (and possibly convert then to POSIXct or Date). Then you can create an irregular time series, e.g. via package its or via package zoo: R> y <- zoo(x[,2], strptime(x[,1], "%Y%m%d")) R> plot(y) hth, Z> Or at the very least, I am unable to find a function that will > grap the second column (y-axis) against the date series (x-axis). If > you could tell me how to graph this type of data, I would greatly > appreciate it. Thank you. > > > Regards, > > John DeAngelis > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
John DeAngelis <john.deangelis <at> moorecap.com> writes: : : Hello, : : I am currently attempting to introduce R at my company and am trying to : import time series data from a text file into R to graph. The format of the : text file is in date, data (e.g., 20040929 3.361). My problem is that I do : not know how to get R to recognize the first column as a business date : series. Or at the very least, I am unable to find a function that will grap : the second column (y-axis) against the date series (x-axis). If you could : tell me how to graph this type of data, I would greatly appreciate it. Thank : you. The most straight forward way is just to read it into a data frame, convert the first column to Date class and then plot: x <- read.table("myseries.dat") colnames(x) = c("date", "value") # label the columns x$date <- as.Date(as.character(x$date), "%Y%m%d") plot(value ~ date, x) However, you might wish to use one of the irregular time series packages in R. These include zoo (in package zoo), its (in package its) and timeSeries (in package fBasics). My preference here would be zoo since it can use the Date class which is particularly suitable for daily data: require(zoo) z <- read.table("myseries.dat") colnames(z) = c("date", "value") z <- zoo(z$value, as.Date(as.character(z$date), "%Y%m%d")) plot(z)