https://github.com/cran/cccd
Raw File
Tip revision: df18892e23666dbba33842956fc8494dc4141140 authored by David J. Marchette on 17 April 2012, 00:00:00 UTC
version 1.01
Tip revision: df18892
rng.R
rng <- function(x=NULL,dx=NULL,r=1, method=NULL,usedeldir=TRUE)
{
   if(is.null(dx)) {
	  if(is.null(x)) stop("One of x or dx must be given.")
	  dx <- as.matrix(dist(x,method=method))
   }
   n <- nrow(dx)
   A <- matrix(0,nrow=n,ncol=n)
   if(is.vector(x)) x <- matrix(x,ncol=1)
   if(usedeldir && ncol(x)==2 && 
	   (length(.find.package("deldir",quiet=TRUE))>0)){
	  require(deldir)
	  del <- deldir(x[,1],x[,2])
	  for(edge in 1:nrow(del$delsgs)){
	     i <- del$delsgs[edge,5]
	     j <- del$delsgs[edge,6]
		 d <- min(apply(cbind(dx[i,-c(i,j)],dx[j,-c(i,j)]),1,max))
		 if(r*dx[i,j] < d){
		    A[i,j] <- 1
		    A[j,i] <- 1
		 }
	  }
   }
   else{
	  diag(dx) <- Inf
	  for(i in 1:n){
		 for(j in setdiff(1:n,i)){
			d <- min(apply(cbind(dx[i,-c(i,j)],dx[j,-c(i,j)]),1,max))
			if(r*dx[i,j] < d){
			   A[i,j] <- 1
			   A[j,i] <- 1
			}
		 }
	  }
   }
	diag(A) <- 0
	out <- graph.adjacency(A,mode="undirected")
	out$layout <- x
	out$r <- r
   out
}

back to top