[R] time segments intersection

[Ricardo Rodriguez] Your XEN ICT Team webmaster at xen.net
Fri Oct 3 00:53:32 CEST 2008


Hi John,

John Kane wrote:
> help("%in%") may be of use. However I don't see any overlap in your example.
>   
You are right! I've choosen an example where the intersection is 0. But we could consider this other case...

endPeriod<-as.POSIXlt("2008-09-30")
startPeriod<-as.POSIXlt("2007-10-01")
endProject<-as.POSIXlt("2007-12-31")
startProject<-as.POSIXlt("2006-12-01")

project <- as.numeric(endProject-startProject)
period <- as.numeric(endPeriod-startPeriod)

I see how to use intersect with numbers as in the example:

intersect(1:10,7:20)

%in% returns a logical vector indicating if there is a match or not, thus it is not an option for us.

*Please, how could I pass the date in seconds to intersect?*

I know how to  get system time in seconds, unclass(Sys.time()), but how could I get endPeriod, startPeriod and so on, so forth, to pass this values to intersect? It is the only way I can figure out to get a vector with the intersecting period. It will be a huge vector in some cases, but I guess I could get its size in anyway and to avoid to print out the values.

Thanks for your help,

Ricardo


-- 
Ricardo Rodríguez
Your XEN ICT Team



More information about the R-help mailing list