Organizes the levels to use for the two inputs. This is useful
for when one wants to merge two vectors that are factors. Ideally, they
have the same levels, in which case those are returned. If they have
overlapping levels, then the levels are merged and sorted (using
sort()
). Otherwise, the levels are dropped (returning NULL
)
organize_levels(x, y, ...)
x, y | Two factor vectors |
---|---|
... | passed to |
vector of levels or NULL
for no levels
set.seed(0) a <- factor(sample(LETTERS, 5), levels = LETTERS) b <- factor(sample(LETTERS, 5), levels = LETTERS) a#> [1] N Y D G A #> Levels: A B C D E F G H I J K L M N O P Q R S T U V W X Y Zb#> [1] B W K N R #> Levels: A B C D E F G H I J K L M N O P Q R S T U V W X Y Zorganize_levels(a, b)#> [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" #> [20] "T" "U" "V" "W" "X" "Y" "Z"