R/nearNeighbour.R

nearNeighbour <- function(distobj, sppVector, names = FALSE){
	distobj <- as.matrix(distobj)
	diag(distobj) <- NA
	aa <- apply(distobj, MARGIN=2, FUN=function(x) which(x == min(x, na.rm = TRUE)))
	bb <- sapply(aa, function(x) names(sort(table(sppVector[x]), decreasing=TRUE)[1]))
	if(names) as.vector(bb) else as.vector(bb == sppVector)
}

Try the spider package in your browser

Any scripts or data that you put into this service are public.

spider documentation built on May 2, 2019, 5:16 p.m.