Re: [R] writing a simple function

From: Roland Rau <roland.rproject_at_gmail.com>
Date: Wed, 13 Feb 2008 09:45:15 -0500

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.
>



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. Received on Wed 13 Feb 2008 - 14:52:10 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 - 15:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive