[R] working with strptime data

Richard Evans revans at jlab.org
Thu Sep 14 16:22:48 CEST 2006


Dear R-forum,

I am looking for a good resource/help on working with POSIXct values and
controlling the pretty x-axis labels and tick marks for a data VS time
plots. Specifically, I wish to do programming logic which creates
different vertical ablines calculations based on the range of times
which i am working on. The default plot results are adequate, but I
would love to make explicit calls on how the x-axis annotates the
timestamps.

Does anyone have example code or know of a good reference for these
kinds of R-programming tasks?


Here's a simplified example:
----------------------------------------------------------
I have a large data set that consists of N pairs of values and
timestamps strings.
Like this:

TheData <- c(1.2,             0.9,             etc...[to the Nth
datapoint])
TheTime <- c("9/1/2006 8:00", "9/1/2006 8:13", etc...[to the Nth
timestamp])

I convert the timestamp strings into POSIXct types as:

TheTime <- as.POSIXct(strptime(TheTime, format="%m/%d/%Y %H:%M"))

And create a plot as such:

plot(MyTime,MyData)

----------------------------------------------------------

And here is a specific question:

How do I calculate the number of months than are spanned between two
POSIXct values?
(i.e. NumOfMonths <- MonthFunction(range(MyTimeStampData))

Thanks-in-advance,
- rich



More information about the R-help mailing list