partition (version 0.1.0)

as_director: Create a custom director

Description

Directors are functions that tell the partition algorithm what to try to reduce. as_director() is a helper function to create new directors to be used in partitioners. partitioners can be created with as_partitioner().

Usage

as_director(.pairs, .target, ...)

Arguments

.pairs

a function that returns a matrix of targets (e.g. a distance matrix of variables)

.target

a function that returns a vector of targets (e.g. the minimum pair)

...

Extra arguments passed to .f.

Value

a function to use in as_partitioner()

See Also

Other directors: direct_distance, direct_k_cluster

Examples

Run this code
# NOT RUN {
# use euclidean distance to calculate distances
euc_dist <- function(.data) as.matrix(dist(t(.data)))

# find the pair with the minimum distance
min_dist <- function(.x) {
  indices <- arrayInd(which.min(.x), dim(as.matrix(.x)))

  #  get variable names with minimum distance
  c(
    colnames(.x)[indices[1]],
    colnames(.x)[indices[2]]
  )
}

as_director(euc_dist, min_dist)

# }

Run the code above in your browser using DataLab