[R] help on loop function

markleeds at verizon.net markleeds at verizon.net
Fri Feb 15 17:14:54 CET 2008


>From: mohamed nur anisah <nuranisah_mohamed at yahoo.com>
>Date: 2008/02/15 Fri AM 07:13:15 CST
>To: r-help at r-project.org
>Subject: [R] help on loop function

a similar ( if not identical ? ) question was asked a few days ago and the answer is at the link below.

http://article.gmane.org/gmane.comp.lang.r.general/106129


>Dear lists,
>   
>  Anysuggestion on how to write a loop function which has nx2 matrix as an input, where each of the row represents an interval. the function should return a mx2 matrix containing the no matched interval of x?? i've tried my own function but it's only applies for 2x2 matrix. 
>   
>  Here is my code:
>   
>  overlap<-function(x,y){
>m=length(x)
>n=length(y)
> for(i in 1:m){
>  for(j in 1:n){
>   if(x[i]>=y[j]) print(TRUE)
>   else print(FALSE)
>     }
>   } 
>  }
>   
>  Many thanks!! 
>   
>  Cheers,
>  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