[R] writing a simple function
    Roland Rau 
    roland.rproject at gmail.com
       
    Wed Feb 13 15:45:15 CET 2008
    
    
  
Hi,
mohamed nur anisah wrote:
> Dear lists,
>    
>   any suggestion on how to write a function to return a TRUE if interval [a,b] overlaps the interval [c,d]. I've tried it but an error occur saying that 'could not find function v ; in addition warning message occur'. Below is my codes.Please help me sort this problem as i'm in process of learning of writing a function. Many thanks
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)
Best,
Roland
>    
>   overlap<-function(m,n){
> t=length(m)
> v=length(n)
> tt=logical(t)
> tv=logical(v)
>  for(i in 1:m){
>   for(i in 1:n){
>   if(v(i,j)<=t(i,j)){
>      tt=T
>      tv=T
>    }
>   }
>  }
> k=c(tt,tv)
> return(k)
> }
>    
>   Regards,
>   Anisah
> 
>        
> ---------------------------------
> 
> 	[[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