Given a distance matrix for sorted objects, compute a hierarchical clustering preserving this order. That is, this is similar to hclust with the constraint that the result's order is always 1:N.

oclust(distances, method = "ward.D2", order = NULL, members = NULL)

## Arguments

distances A distances object (as created by stats::dist). The clustering method to use (only ward.D and ward.D2 are supported). If specified, assume the data will be re-ordered by this order. Optionally, the number of members for each row/column of the distances (by default, one each).

## Value

A clustering object (as created by hclust).

## Details

If an order is specified, assumes that the data will be re-ordered by this order. That is, the indices in the returned hclust object will refer to the post-reorder data locations, **not** to the current data locations.

This can be applied to the results of slanted_reorder, to give a "plausible" clustering for the data.

## Examples

clusters <- slanter::oclust(dist(mtcars), order=1:dim(mtcars)[1])
clusters\$order
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26 27 28 29 30 31 32