[Vegan-commits] r2852 - pkg/vegan/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Feb 7 10:33:46 CET 2014
Author: jarioksa
Date: 2014-02-07 10:33:46 +0100 (Fri, 07 Feb 2014)
New Revision: 2852
Modified:
pkg/vegan/R/as.hclust.spantree.R
Log:
use hclustMergeOrder in as.hclust.spantree
Modified: pkg/vegan/R/as.hclust.spantree.R
===================================================================
--- pkg/vegan/R/as.hclust.spantree.R 2014-02-07 09:18:50 UTC (rev 2851)
+++ pkg/vegan/R/as.hclust.spantree.R 2014-02-07 09:33:46 UTC (rev 2852)
@@ -23,36 +23,13 @@
labs <- -seq_len(npoints)
merge <- matrix(0, nrow=npoints-1, ncol=2)
for(i in 1:nrow(merge)) {
- ## add items of labs, keep tighter cluster on the left
merge[i, ] <- c(labs[dad[i]], labs[kid[i]])
## update labs for the current group and its kids
labs[labs %in% labs[c(dad[i], kid[i])]] <- i
}
- ## Get order of leaves with recursive search from the root.
- visited <- matrix(FALSE, nrow = nrow(merge), ncol=ncol(merge))
- order <- numeric(npoints)
- ind <- 0
- ## "<<-" updates data only within this function, but outside the
- ## visit() function.
- visit <- function(i, j) {
- if(visited[i,j])
- return(NULL)
- else {
- visited[i,j] <<- TRUE
- }
- if (merge[i,j] < 0) {
- ind <<- ind+1
- order[ind] <<- -merge[i,j]
- if (j == 1)
- visit(i, 2)
- } else {
- visit(merge[i,j], 1)
- visit(merge[i,j], 2)
- }
- }
- visit(nrow(merge), 1)
- visit(nrow(merge), 2)
-
+
+ order <- hclustMergeOrder(merge)
+
out <- list(merge = merge, height = x$dist[o], order = order,
labels = x$labels, method = "spantree", call =
match.call())
More information about the Vegan-commits
mailing list