Michael Mastroianni
2000-Sep-22 14:44 UTC
[R] Newbie question - handling dates as x-axis variable
Hi, all. Please forgive my ignorance as I'm just beginning to investigate R for use in my company as a primary analytical tool ... I have data which I've read into a data frame with the following command: mkt <- read.csv("h:/qdamrtm.csv",header=T) I'd like to investigate the relationship(s) (or lack thereof) between the given variables, and have developed a variety of plots that really make me appreciate how powerful R is, even when applied in a very rudimentary fashion. My question is, is there an elegant way to treat the date data such that I can plot variables against x-axis date labels, specify ranges of dates, and calculate differences between dates ? I am beginning to look at the packages like "chron" and time series information now. The workaround I've adopted merely uses the row index of the data frame as the x-axis variable, and I've "pasted" the start and end dates into the x-axis title to associate the plotted indices with a date range (which is a bit of a kludge, I think). If I've gleaned anything at all from the R documentation, I should be trying to treat my data frame as an object to be manipulated, and should be able to develop functions or procedures which allow me to handle dates in a simple and direct manner. Any advice/guidance/tips are much appreciated as I have *tons* of this kind of data to cut my teeth on ... (Also, kudos to the R developers: what an incredible job in creating a "numerical laboratory" environment. I'm especially pleased that I can investigate R in a Windows environment knowing that it's available as we move to Linux ...) Thanks in advance for any help -- Mike Mastroianni =================================For reference, the CSV data looks like this: "WKDAY","HR","DAYT","DAMMKT","RTMMKT" "Fri",0,"01/07/00",16.16,17.51 "Fri",0,"01/14/00",21.91,51.15 "Fri",0,"01/21/00",31.25,21.38 "Fri",0,"01/28/00",36.01,41.77 "Fri",1,"01/07/00",15.24,15.32 "Fri",1,"01/14/00",20.23,31.48 "Fri",1,"01/21/00",30.40,12.98 "Fri",1,"01/28/00",28.27,38.86 .... "Wed",23,"08/23/00",23.11,39.99 "Wed",23,"08/30/00",46.48,58.77 "Wed",23,"09/06/00",32.63,9.09 "Wed",23,"09/13/00",44.11,44.89 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley
2000-Sep-22 15:39 UTC
[R] Newbie question - handling dates as x-axis variable
On Fri, 22 Sep 2000, Michael Mastroianni wrote:> Hi, all. Please forgive my ignorance > as I'm just beginning to investigate > R for use in my company as a primary > analytical tool ... > > I have data which I've read into a data frame > with the following command: > > mkt <- read.csv("h:/qdamrtm.csv",header=T) > > I'd like to investigate the relationship(s) > (or lack thereof) between the given variables, > and have developed a variety of plots that > really make me appreciate how powerful > R is, even when applied in a very rudimentary > fashion. > > My question is, is there an elegant way to > treat the date data such that I can plot > variables against x-axis date labels, specify > ranges of dates, and calculate differences > between dates ? I am beginning to look > at the packages like "chron" and time series > information now. The workaround I've adopted > merely uses the row index of the data frame > as the x-axis variable, and I've "pasted" the > start and end dates into the x-axis title to > associate the plotted indices with a date > range (which is a bit of a kludge, I think). > > If I've gleaned anything at all from the R > documentation, I should be trying to > treat my data frame as an object to be > manipulated, and should be able to > develop functions or procedures which > allow me to handle dates in a simple > and direct manner. > > Any advice/guidance/tips are much appreciated > as I have *tons* of this kind of data to > cut my teeth on ...Package chron is along the lines you need. However, R 1.2.0 will have its own date/time classes and can do all the things you mention, plus give you examples to copy, and I think that these will in time supersede chron. (The time series stuff in package ts is only for regularly-spaced time series.) Look's like you are on Windows. You can either compile an R-devel snapshot yourself, or get a pre-compiled one from http://www.stats.ox.ac.uk/pub/bdr/RWin/Rpre (Do read the README first, though, and remember this is a snapshot.) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._