![](../logo.png)
Number of clusters in a partition (per connected component)
Source:R/partition_tools.R
nbClusters.Rd
Give the number of clusters in a partition. This number can be the total number or the number in each connected component.
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 ofpartition
.
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