Re: [R] writing a simple function

From: Roland Rau <>
Date: Wed, 13 Feb 2008 12:51:16 -0500


Ben Bolker wrote:
> Roland Rau <roland.rproject <at>> writes:

>> does this do what you want?
>> overlap <- function(a,b,c,d) {
>> 	all(c:d %in% a:b)
>> }
>> overlap(1,5,3,4)
>> overlap(1,2,3,4)

> Do you really want this to be discrete? How about
> overlap <- function(a,b,c,d) {
> a<c && b>d
> }
you are absolutely right.[1]
I assume with discrete you mean integers? I think the bigger problem with my function is that it makes way too many comparisons than are actually necessary (memory and time problems).

What about the following function:
overlap <- function(intval1, intval2) {

   (min(intval1) < min(intval2)) && (max(intval1) > max(intval2)) }


[1] I realized the problems with my solution almost as soon as I sent the email. But I was on a way to a meeting and there was no more time to correct it at that moment. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 13 Feb 2008 - 18:00:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 13 Feb 2008 - 19:30:14 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive