[R] Chron object in time series plot

David Winsemius dwinsemius at comcast.net
Tue Oct 19 18:53:43 CEST 2010


On Oct 19, 2010, at 12:19 PM, Manta wrote:

>
>
> David Winsemius wrote:
>>
>>
>> You seen to be under the mistaken impression that the internal
>> representation of DateTime classes of 08:00 would be 80000. Since the
>> internal representation of time is in seconds, the even number hours
>> would be at integer multiples of 60*60. In addition the conversion of
>> numeric to string in this situation may present some need to check  
>> for
>> missing leading "0"'s. You ether need to describe the data situation
>> more completely or adjust your expectations (or both).
>>
>> ?as.POSIXct
>> ?strptime
>>
>> -- 
>> David.
>>
>>
>
> Thanks for the quick reply David.
>
> What I need is a simple conversion that can say 80000=08:00,  
> 94500=09:45 and
> 100000=10:00 and so on.
> I agree with you that the extra leading "0s" would need an extra  
> check.

I'm having some difficulty understanding what you want but see if this  
gets you further:

 > example <-"070002,1
+ 070002,0
+ 070002,0
+ 070003,1
+ 070003,0
+ 070003,0
+ 070003,0
+ 070003,0
+ 100210,0
+ 100210,0
+ 100210,0
+ 100210,0
+ 100210,0
+ 100210,0
+ 100210,0"
 > timedf <- read.table(textConnection(example),  
colClasses=c("character", "numeric"), sep=",", header=FALSE)
 > str(timedf)
'data.frame':	15 obs. of  2 variables:
  $ V1: chr  "070002" "070002" "070002" "070003" ...
  $ V2: num  1 0 0 1 0 0 0 0 0 0 ...
 > as.POSIXct(timedf$V1, format="%H%M%S", origin="1970-01-01")
  [1] "2010-10-19 07:00:02 EDT" "2010-10-19 07:00:02 EDT"
  [3] "2010-10-19 07:00:02 EDT" "2010-10-19 07:00:03 EDT"
  [5] "2010-10-19 07:00:03 EDT" "2010-10-19 07:00:03 EDT"
  [7] "2010-10-19 07:00:03 EDT" "2010-10-19 07:00:03 EDT"
  [9] "2010-10-19 10:02:10 EDT" "2010-10-19 10:02:10 EDT"
[11] "2010-10-19 10:02:10 EDT" "2010-10-19 10:02:10 EDT"
[13] "2010-10-19 10:02:10 EDT" "2010-10-19 10:02:10 EDT"
[15] "2010-10-19 10:02:10 EDT"

>
> The data situation is the following: I have several thousands of
> observations  each day and I want to average them out throughout  
> bins of a
> specified size (either 15 or 5 minutes).

That was not clear to me. The phrase "....average them out throughout  
bins of a specified size..." is not an unambiguous operation. This  
needs a good example that provides sample input and also expected  
output.

> An example of the data follows,
> where the first column is the time and the second represents seconds  
> between
> different events.

Notice that I read them in as character variables which preserved the  
leading zeroes.

>
> example.txt
>
> 070002,1
> 070002,0
> 070002,0
> 070003,1
> 070003,0
> 070003,0
> 070003,0
> 070003,0
> ...
> 100210,0
> 100210,0
> 100210,0
> 100210,0
> 100210,0
> 100210,0
> 100210,0
> ...
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002358.html
> Sent from the R help mailing list archive at Nabble.com.
-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list