[R] overlap between line segments

Karla Shikev karlashikev at gmail.com
Mon Jul 13 23:44:23 CEST 2015


Hi there,

This is a newbie question, and I'm sure there are simple ways to do this,
but I've spent my entire afternoon and I couldn't get it to work.

Imagine that I got my samples distributed along a transect and my data
refer to the first and last occurrences of each sample. For instance:

> dat<-matrix(c(1,3,2.5,4), ncol=2, byrow=TRUE)
> dat
     [,1] [,2]
[1,]  1.0    3
[2,]  2.5    4


The first line indicates that the first and last occurrences of this
subject were 1 and 3, respectively, whereas the second subject was found
between 2.5 and 4.

I need a simple way to calculate the overlap of their extents (0.5 in this
case). This way should provide 0 if there is no overlap, and it should also
work in the case where one subject is found only within the extent of the
second subject.

Any help will be greatly appreciated.

Karla

	[[alternative HTML version deleted]]



More information about the R-help mailing list