Skip to contents

Give the number of clusters in a partition. This number can be the total number or the number in each connected component.

Usage

nbClusters(partition, components = NULL)

Arguments

partition

a partition vector.

components

a vector giving for each element its connected component. If NULL (default) components will be ignored. Otherwise must be a vector of the same length of partition.

Value

If components is NULL, the total number of clusters in partition (positive integer). Otherwise a named vector of positive integers of length the number of connected components and giving the number of clusters per connected component.

Examples

nbClusters(c(1L, 2L, "x", 1L)) # 3
#> [1] 3