R/cutcluster.R

Defines functions cutcluster

cutcluster <- function(x,c=2){
  # c: number of clusters
  x <- x[,sapply(x,is.numeric)]
  p <- ncol(x)
  co <- cor(x,use = "pairwise.complete.obs")
  distx <- 1-as.dist(co)
  hc <- hclust(distx,method = "average")
  al <- seriate(distx,method="OLO",control=list(hclust=hc))
  ord <- get_order(al)
  cl <- cutree(hc,k=c)[ord]
  cuts <- vector(length=c-1)
  i <- 1  
  for(j in 1:(p-1)){
    if(cl[j]!=cl[j+1]) {
      cuts[i] <- j
      i <- i+1
    }
  }
  return(cuts)
}

Try the mbgraphic package in your browser

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

mbgraphic documentation built on May 2, 2019, 2:45 a.m.