relabel_class {cola} | R Documentation |
Relabel class IDs according to the reference ID
relabel_class(class, ref, full_set = union(class, ref))
class |
a vector of class IDs. |
ref |
a vector of reference IDs. |
full_set |
the full set of levels. |
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
.
A data frame with three columns:
original IDs
adjusted IDs
reference IDs
The mapping between adjusted IDs and original IDs are stored as the map
attribute of the data frame.
class = c(rep("a", 10), rep("b", 3)) ref = c(rep("b", 4), rep("a", 9)) relabel_class(class, ref)