This is really confusing behavior:
x <- factor(1:3, levels = 1:4, labels = letters[1:4])
x
# [1] a b c
# Levels: a b c d
labels(x)
# [1] "1" "2" "3"
levels(x)
# [1] "a" "b" "c" "d"
Why does labels()
return the values given to levels =
(though filtered to what was actually used, for some reason), while levels()
returns what was given to labels =
(which is also given as Levels:
when inspecting x
)?