[R] cumulative time durations of specified periods (chron)
Sebastian Luque
spluque at gmail.com
Mon Jun 12 05:54:48 CEST 2006
Hi,
Say we have two chron vectors representing start and end date/times of an
event, respectively:
R> (xfrom <- chron(seq(1.25, 11, 3.25)))
[1] (01/02/70 06:00:00) (01/05/70 12:00:00) (01/08/70 18:00:00)
[4] (01/12/70 00:00:00)
R> (xto <- chron(as.numeric(xfrom) + seq(1.5, 2.25, 0.25)))
[1] (01/03/70 18:00:00) (01/07/70 06:00:00) (01/10/70 18:00:00)
[4] (01/14/70 06:00:00)
and we would like to know how much time is included in a number of
intervals within each event. We can define the intervals with two chron
vectors:
R> (xt0 <- times(c(0.50, 0)))
[1] 12:00:00 00:00:00
R> (xt1 <- times(c(1 - (1 / 86400), 0.25)))
[1] 23:59:59 06:00:00
So for the first event, 01/02/70 06:00:00 to 01/03/70 18:00:00, the
interest is to find how much time corresponds to periods 12:00:00 -
23:59:59 and 00:00:00 - 06:00:00.
I began writing a function to accomplish this task, but am at an impasse.
The archives may have something on this, but I haven't found a good search
query for it, so I'd appreciate some pointers. Thanks in advance.
Cheers,
--
Seb
More information about the R-help
mailing list