Skip to content

Creating appropriate time axis for data

4 messages · Uwe Ligges, Tony Stocker, Jeff Newmiller

#
Hello,

I am dealing with data stored in a database as a 'time' object.  I
export the data from the database to a text file and utilize the
'time_to_sec()' function of the database to convert the human readable
time (HH:MM:SS) to seconds so that I can use R to do analysis and
create charts of the data.  I do not need or use days or dates in the
data, and the data range is from 07:00:00 to 18:00:00 or 25200-64800
seconds.  However when I visualize the data in charts I do not want a
scale that runs from 25200-64800 seconds, but rather in the HH:MM:SS
format.  Is there a relatively straight-forward and easy to use way to
do this?

Thanks,
Tony
#
On 12.12.2011 17:44, Tony Stocker wrote:
I get

 > time_to_sec
Error: object 'time_to_sec' not found

If it is in a package, please tell us which one you are referring to.
Yes, e.g.:

t <- strptime(c("07:00:00", "18:00:00"), "%H:%M:%S")
y <- rnorm(2)
plot(t, x)

Uwe Ligges
#
2011/12/12 Uwe Ligges <ligges at statistik.tu-dortmund.de>:
Sorry for the double post but the first message was held for so long
that I figured there was a problem with the email address I was using
so I unsubscribed that one and resubscribed the other one.
The time_to_sec() function is inside the database (in this case
MySQL).  I'm using it solely because R doesn't want to deal with the
times as normally outputted (HH:MM:SS) because it sees them as a
character object and not a numerical or time object.  By converting
these time fields to seconds when I export them from the database I
provide something that R can work with natively apparently.
Does this method supercede  the original y-axis label or supplement
it?  Will the data be correctly located along the y-axis if it's in
seconds?

I thought I had looked at strptime() and it required day/date info to
be listed not just time.  Based on your example I'm assuming that I
was incorrect in that assumption.

Thanks for this suggestion I'll give it a try with my data and see if
it does what I'd like it to do.  I appreciate the help.
-Tony
#
"Does not support natively" isn't accurate. It is common to import date/time values as character and then use strptime or as.Date or other conversion function as desired. This may at first seem tedious, but it does provide flexibility.
---------------------------------------------------------------------------
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.
Tony Stocker <tonystocker at mail.com> wrote: