components: Find connected components

componentsR Documentation

Find connected components

Description

The components function finds connected components in a numeric array. The kernel determines which neighbours are considered connected (e.g. including or excluding diagonal neighbours), and will usually have width 3 in each dimension.

Usage

components(x, kernel, ...)

## Default S3 method:
components(x, kernel, ...)

Arguments

x

Any object. For the default method, this must be coercible to an array.

kernel

An object representing the kernel to be used, which must be coercible to an array. It must have odd width in all dimensions, but does not have to be isotropic in size. The kernel's dimensionality may be less than that of the target array, x. See kernels for kernel-generating functions.

...

Additional arguments to methods.

Value

An array of the same dimension as the original, whose integer-valued elements identify the component to which each element in the array belongs. Zero values in the original array will result in NAs.

Author(s)

Jon Clayden <code@clayden.org>

See Also

kernels for kernel-generating functions.

Examples

x <- c(0,0,1,0,0,0,1,1,1,0,0)
k <- c(1,1,1)
components(x,k)

mmand documentation built on Feb. 16, 2023, 9:22 p.m.