I have a dataset that does not contain now but later a defined order.
For instance
library(tidyverse)
x <- c("a")
fct_relevel("d", c("a", "b", "c", "d"))
[1] d
Levels: d
Warning message:
3 unknown levels in `f`: a, b, and c
fct_expand("d", c("a", "b", "c", "d"))
[1] d
Levels: d a b c
How can I use fct_relevel() together with fct_expand() to pre-define the order in the order of the levels "a b c d" even if the levels are unknown at the current time? (Another dplyr solution would also be fine)
Thank you very much!
If you're working with tibbles, you can use
fct_expandandcomplete: