[R] generating a sequence of seconds
wdunlap at tibco.com
Tue Aug 12 22:23:48 CEST 2014
> Again, in my opinion, all time date should be recorded in GMT.
It depends on context. If you are studying traffic flow or
electricity usage, then you want local time with all its warts
(perhaps stated as time since 3am so any daylight savings time
problems are confined to a small portion of the data), perhaps along
with time since sunrise and time since sunset.
If you are studying astronomy, then UTC is appropropriate.
On Tue, Aug 12, 2014 at 1:16 PM, John McKown
<john.archie.mckown at gmail.com> wrote:
> On Tue, Aug 12, 2014 at 2:26 PM, Erin Hodgess <erinm.hodgess at gmail.com>
>> What I would like to do is to look at several days and determine
>> that happened at times on those days. I don't really care which days, I
>> just care about what time.
>> Thank you!
> Ah! A light dawns. You want to subset your data based on some part of the
> time. Such as "between 13:23:00 and 15:10:01 of each day in the sample."
> Ignoring the DST issue, which I shouldn't. It is left as an exercise for the
> reader. But usually 13:23 is 13*3600+23*60, 48180, seconds after midnight.
> 15:10:01 is 15*3600+10*60+1, 54601, seconds after midnight. Suppose you have
> a data.frame() in a variable called myData. Further suppose that the POSIXct
> variable in this data.frame is called "when". You want to subset this into
> another data.frame() and call it subsetMyData.
> subsetMyData<-myData[as.integer(myData$when)%%86400 >= 48180 &
> as.integer(myData$when)%%86400 <= 54601,];
> Yes, this is ugly. You might make it look nicer, and be easier to
> understand, by:
> startTime <- as.integer(as.difftime("13:23:00",units="secs")); # start on or
> after 1:23 p.m.
> endTime <- as.integer(as.difftime("15:10:01",units="secs")); # end on or
> before 3:10:01 p.m.
> testTime <- as.integer(myData$when)%%86400; #convert to seconds and
> eliminate date portion.
> subsetMyData <-myData[testTime >= startTime & testTime <= endTime,];
> This will work best if myData$when is in GMT instead of local time. Why? No
> DST worries. Again, in my opinion, all time date should be recorded in GMT.
> Only convert to local time when displaying the data to an ignorant user who
> can't handle GMT. Personally, I love to tell people something like: "it is
> 13:59:30 zulu". In my time zone, today, that is 08:59:30 a.m.
> There is nothing more pleasant than traveling and meeting new people!
> Genghis Khan
> Maranatha! <><
> John McKown
More information about the R-help