relabel_class {cola}R Documentation

Relabel class IDs according to the reference ID

Description

Relabel class IDs according to the reference ID

Usage

relabel_class(class, ref, full_set = union(class, ref))

Arguments

class

a vector of class IDs.

ref

a vector of reference IDs.

full_set

the full set of levels.

Details

In partition, the exact value of the class ID is not of importance. E.g. for two partitions a, a, a, b, b, b, b and b, b, b, a, a, a, a, they are the same partitions although the labels of a and b are switched in the two partitions. Here relabel_class function switches the labels in class vector accoring to the labels in ref vector to maximize sum(class == ref).

Mathematically, this is called linear sum assignment problem and is solved by solve_LSAP.

Value

A data frame with three columns:

The mapping between adjusted IDs and original IDs are stored as the map attribute of the data frame.

Examples

class = c(rep("a", 10), rep("b", 3))
ref = c(rep("b", 4), rep("a", 9))
relabel_class(class, ref)

[Package cola version 1.0.0 Index]