date and time coding question
The difference of two POSIXct values is of type difftime. You should not think of difftime as having units. Rather, you should think of the result of converting from difftime to numeric (using as.numeric) as the opportunity (or rather requirement) to specify what time units you want. If you let R print the difftime object unconverted, it will print with whatever units seem appropriate given the magnitude of the difftime.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
"MacQueen, Don" <macqueen1 at llnl.gov> wrote:
I think you probably want
format='%m/%d/%y %H:%M')
(lower case "y")
diff() as suggested by Jeff Newmiller is good, except that I don't know
how to control the units using diff().
## so a method that allows specifying units other than hours would be,
for
example,
datetime <-c("1/1/13 00:00","1/1/13 12:00","1/2/13 00:00","1/2/13
12:00")
datetime <-as.POSIXct(datetime,format='%m/%d/%y %H:%M')deltas <-
difftime(
datetime[-1], datetime[-length(datetime)] , units='min')
-Don