R/getNumberOfClusters.R

Defines functions getNumberOfClusters

Documented in getNumberOfClusters

#' Get the number of clusters of a network.
#'
#' @template arg_network
#' @return [\code{integer(1)}]
#'   Number of clusters.
#' @note For simple random or grid networks this function always returns 1.
#' @export
getNumberOfClusters = function(x) {
  assertClass(x, "Network")
  n.cluster = 1L
  if (testClass(x, "ClusteredNetwork")) {
    # NOTE: depots are encoded as special cluster members of the depot 0.
    # we filter these out!
    membership = x$membership[which(x$membership != 0)]
    n.cluster = length(unique(membership))
  }
  n.cluster
}

Try the netgen package in your browser

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

netgen documentation built on Jan. 9, 2020, 1:07 a.m.