which.site <- function(di, dist, print=T) { # given integers of observations in a distance object # identify the pair of sites involved # input: # di: scalar or vector of integers, e.g. from identify # dist: distance object if ((attr(dist,'Diag') != F) & (attr(dist,'Upper') != F)) { stop('Distance matrix must be lower triangular without a diagonal') } nsamp <- attr(dist,'Size') ncol <- rep(1:(nsamp-1), seq(nsamp-1,1,-1)) nrow <- NULL for (i in 2:nsamp) { nrow <- c(nrow,i:nsamp) } sitenames <- attr(dist,'Labels') temp2 <- cbind(Row=sitenames[nrow[di]],Col=sitenames[ncol[di]]) temp <- cbind(Row=nrow[di],Col=ncol[di]) dimnames(temp)[[1]] <- dimnames(temp)[[1]] <- di if (print) {print(temp2, quote=F) } invisible(temp) }