Skip to contents

Derive factor levels from another factor with unique pair-wise matches

Usage

fct_derive(new, old)

Arguments

new

A vector

old

A factor

Value

A factor

Examples

old <- factor(LETTERS[1:5], LETTERS[c(3, 2, 1, 5, 4)])
old
#> [1] A B C D E
#> Levels: C B A E D
new <- letters[1:5]
new
#> [1] "a" "b" "c" "d" "e"
factor(new)
#> [1] a b c d e
#> Levels: a b c d e
fct_derive(new, old)
#> [1] a b c d e
#> Levels: c b a e d