[R-sig-eco] altitudinal overlap

Karla Shikev karlashikev at gmail.com
Tue Jul 14 15:19:38 CEST 2015


Excellent. Thanks!

On Tue, Jul 14, 2015 at 5:08 AM, Stefano Leonardi <
stefano.leonardi at gmail.com> wrote:

>
> The first think that came to my mind:
>
> overlap <- function(v1,v2) {
> ov <-min(max(v1), max(v2)) - max(min(v1), min(v2))
> ifelse(ov > 0, ov, 0)
> }
>
> overlap(dat[1,], dat[2,])
> [1] 0.5
>
>
> Ciao
> Stefano
>
> On 14/07/2015 01:03, Karla Shikev wrote:
>
>> 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 the altitudinal range of different species. 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 this species is found between 1 and 3,
>> whereas the second species 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--
>>
> ======================================================================
>  Stefano Leonardi
>  Dipartimento di Bioscienze
>  Universita` di Parma
>  Viale Usberti 11a                             Phone : +39-0521-905659
>  43124 PARMA  (Italy)                          Fax   : +39-0521-905402
>
>  Il mio photoblog:                http://stefanoleonardi.wordpress.com
> ======================================================================
>

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list