[R] Creating appropriate time axis for data
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Tue Dec 13 13:23:43 CET 2011
"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:
>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
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list