| To: | "'David L Lorenz'" <lorenz@usgs.gov>, "'Kim Elmore'" <Kim.Elmore@noaa.gov> |
|---|---|
| Subject: | Re: Dates and Times in S-Plus |
| From: | "Eric Zivot" <ezivot@u.washington.edu> |
| Date: | Fri, 6 Apr 2007 12:39:13 -0700 |
| Cc: | "'S-News'" <s-news@wubios.wustl.edu>, <s-news-owner@lists.biostat.wustl.edu> |
| In-reply-to: | <OF6C12110D.D817F1A8-ON862572B5.00627A23-862572B5.006482F6@usgs.gov> |
| Thread-index: | Acd4eAKy2r+mc8XVS1uDCuuMsUsIHgACtm4w |
|
You can also subset timeDate and timeSeries objects
directly using the timeEvent function. For example, to index the elements of the
FinMetrics timeSeries singleIndex.dat between the periods 3/1/1992 and 1/31/1993
use
> singleIndex.dat[timeEvent("3/1/1992",
"1/31/1993")]
This trick is extremely helpful in plotting subsets of
timeSeries data, but it only works in splus 7 and above.
From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of David L Lorenz Sent: Friday, April 06, 2007 11:18 AM To: Kim Elmore Cc: S-News; s-news-owner@lists.biostat.wustl.edu Subject: Re: [S] Dates and Times in S-Plus Kim, There are a lot of thing to consider when making plots of date/time data, including getting ticks in the correct place and correct labels. We are trying to develop functions that will plot the data correctly and get nice ticks and correct labels. I don't have anything for hourly data right now, but when we do get a good product, those functions will be publically available. Here's basically the approach I would take: 1. For the GUI and command, I'd generate a data.frame that contains the ticks and labels I wanted. Use the timeSeq() function to generate ticks: > timeSeq("11/29/2007 14:15:00", by='hours', length.out=6, align.by=T, extend=T) [1] 11/29/2007 14:00:00.000 11/29/2007 15:00:00.000 11/29/2007 16:00:00.000 [4] 11/29/2007 17:00:00.000 11/29/2007 18:00:00.000 11/29/2007 19:00:00.000 Use the hms() function on those data to extract the hour and put that into another column for the labels. You can further format them any way you wish. 2. For the GUI plot, set the major ticks to use a column in a separate data set and choose the one you created in step one. Do the same for labels. 3. To subset the data, use something like: DateTime >= timeDate("11/29/2007 14:15:00") & DateTime <= timeDate("11/29/2007 18:15:00") in your subsetting _expression_, assuming that the date/time column name is DateTime. 4. For the command line version, I'd convert everything to double for the date/time axis, set the axis type to 'i' or 's' and not draw anything on that axis. Then go back and draw the axis, put in the ticks and labels. Good luck. Dave
I've never much worked with dates and times, but find that I must now do so. I'm doing some very basic EDA and using the GUI to generate some plots. When making plots using the GUI, how do I control the span of the date axis? I'm aware that S-Plus encodes the date in a manner similar to unix/linux, but I don't know how to define things like tic marks in terms of, say hours. For example, if I want a tic mark every hour, how do I declare that? Using command line plots, how would I subset the data such that I plotted only data between, say, 11/29/2007 14:15:00 and 11/29/2007 18:15:00? All data are currently in a data.frame and the data type for the dates column is timeDate. I'm using S-Plus 7.0.6 under Windows XP. Kim Elmore -------------------------------------------------------------------- This message was distributed by s-news@lists.biostat.wustl.edu. To unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with the BODY of the message: unsubscribe s-news |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Dates and Times in S-Plus, David L Lorenz |
|---|---|
| Next by Date: | SENSORCOMM 2007 || International Conference on Sensor Technologies and Applications || October 14-20, 2007 - Valencia, Spain, SENSORCOMM 2007 |
| Previous by Thread: | Re: Dates and Times in S-Plus, David L Lorenz |
| Next by Thread: | SENSORCOMM 2007 || International Conference on Sensor Technologies and Applications || October 14-20, 2007 - Valencia, Spain, SENSORCOMM 2007 |
| Indexes: | [Date] [Thread] [Top] [All Lists] |