[R] Creating appropriate time axis for data

Tony Stocker tonystocker at mail.com
Mon Dec 12 22:32:32 CET 2011


2011/12/12 Uwe Ligges <ligges at statistik.tu-dortmund.de>:
> On 12.12.2011 17:44, Tony Stocker wrote:

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.

>>
>> 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()'
>
>
> 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.

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.
>
>
>> 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?
>
>
> Yes, e.g.:
>
> t <- strptime(c("07:00:00", "18:00:00"), "%H:%M:%S")
> y <- rnorm(2)
> plot(t, x)
>
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.

> Uwe Ligges

-Tony



More information about the R-help mailing list