[R] find overlap between intervals - Correction

Juan Manuel Barreneche jumanbar at gmail.com
Wed Oct 31 16:37:45 CET 2007


I'm not sure if i got the idea of what you want. At fist i thought that
you wanted this output:

Output:
  290  380
  380  440
  440  443
  443  468

to get it, you can use the following function:

intervals <- function(Input)
{
	all <- c(Input$Start, Input$End)
	numbers <- sort(all[-which(duplicated(all))])
	Output <- NULL
	for(i in 1:(length(numbers) - 1))
	{
		Output <- rbind(Output, c(numbers[i], numbers[i+1]))
	}
	Output
}
## then write:
intervals(Input)


but your output it's a little diferent:

CORRECTED Desired output:
> Start End
> 290   380
> 380   440
> 443   468

and i noticed too late... ¿maybe you missed one interval (440 to 443) in
the desired Output?

JM

On Wed, 2007-10-31 at 15:01 +0100, João Fadista wrote:
> Dear all,
> Sorry for the previous email. I had a wrong example output:
>  
> 
> Input:
> Start End
> 440   443 
> 380   443 
> 290   468
>  
> CORRECTED Desired output:
> Start End
> 290   380
> 380   440
> 443   468
>  
> 
> Best regards,
> Joo Fadista
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list