Extracts the reference or a specific level the supplied factor, returning it as a factor with the same levels as the one supplied.
Examples
f <- factor(sample(letters[1:5], 100, replace = TRUE))
# the reference level
ref_level(f)
#> [1] a
#> Levels: a b c d e
# a specific level
level(f, level = "b")
#> [1] b
#> Levels: a b c d e
# note that the levels will always match the input factor
identical(levels(f), levels(ref_level(f)))
#> [1] TRUE
identical(levels(f), levels(level(f, "c")))
#> [1] TRUE