mgx <- function(l,r) { dexarr <- array(dim=c(0,2)) ir <- 1 for ( il in 1:(length(l$t2)-1) ) { while( l$t1[il] >= r$t3[ir] ) { dexarr <- rbind( dexarr, c(NA,ir)) ir <- ir+1; } if( l$t3[il] < r$t1[ir] ) dexarr <- rbind( dexarr, c(il,NA)) else { dexarr <- rbind( dexarr, c(il,ir)) ; ir <- ir+1; } } dexarr} mg <- function(l,r) { mgx( rbind(l[1:3],c(9999999,Inf,Inf)),rbind(r[1:3],c(9999999,Inf,Inf))) }