I have data which includes Date
as well as Time enter
and Time exit
. These latter two contain data like this: 08:02
, 12:02
, 23:45
etc.
I would like to manipulate the Time eXXX
data - for example, substract Time enter
from Time exit
to work out duration, or plot the distributions of Time enter
and Time exit
, e.g. to see if most entries are before 10:00, or if most exits are after 17:00.
All the packages I've looked at require a date to precede the time, e.g. 01/02/2012 12:33
.
Is this possible, or should I simply append an identical date to every time for the sake of calculations? This seem a bit messy!
Would something like that work?
Testing:
Came across a similar issue and was inspired by this post. @G. Grothendieck and @David Arenburg provided great answers for transforming the time.
For comparison, I feel forcing the time into numeric helps. Instead of comparing
"11:22:33"
with"9:00:00"
, comparingas.numeric(hms("11:22:33"))
(which is40953
seconds) andas.numeric(hms("9:00:00"))
(32400
) would be much easier.The above example shows 11:22:33 is between 9AM and 5PM.
To extract just time from the date or POSIXct object,
substr("2013-10-01 11:22:33 UTC", 12, 19)
should work, although it looks stupid to change a time object to string/character and back to time again.Converting the time to numeric should work for plotting as @G. Grothendieck descirbed. You can convert the numbers back to time as needed for x axis labels.
Use the
"times"
class found in the chron package:Graphics: