[R] time segments intersection

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 4 02:38:33 CEST 2008


On Fri, Oct 3, 2008 at 7:47 PM, [Ricardo Rodriguez] Your XEN ICT Team
<webmaster at xen.net> wrote:
> Hi!
>
>
> [Ricardo Rodriguez] Your XEN ICT Team wrote:
>>
>> Thanks Gabor,
>>
>> Gabor Grothendieck wrote:
>>>
>>> If those do not work try installing some other packages, e.g. chron,
>>> to see if you can install anything.  If you still have problems there
>>> is something wrong with your installation.   Ask on the r-sig-mac list.
>>>
>
>
> Zoo installed. There is a "[R-SIG-Mac] /bin/sh: tar: command not found"
> thread with the details. I don't understand yet why and when the problem
> originated, but at least Zoo and the other binaries are installing fine no.
>
> Thanks for your proposal. But do you think that it is more effective/quick
> to use merge instead of intersect? Mark's idea gives a numeric output with
> the number of days the two segments intersect. Please, WDYT? Thanks!
>
> Greetings,
>
> Ricardo
>
> --
> Ricardo Rodríguez
> Your XEN ICT Team

Mark did not post his response so I don't know what it
is.   How you do it may depend on your setup which was
not entirely clear from the question since it started out
as if the two series were the inputs and then seemed to be
assuming the time ranges were.

Here are a few possibilities assuming z1 and z2
from my prior post.  Depending on what you want
you may need to add 1.

diff(range(time(merge(z1, z2, all = FALSE))))

diff(range(intersect(time(z1), time(z2))))

r1 <- range(time(z1))
r2 <- range(time(z2))
pmin(r1, r2)[2] - pmax(r1, r2)[1]

The first one generalizes to N series immediately.  The
second does not but is slightly shorter (although abbreviation
of the first could get that one even shorter).  The last
reduces the series to time ranges and then operates on
those.



More information about the R-help mailing list