powered by
Helper function factor inputs in order of appearance, or per the levels that you provide.
h_factor(df, var, levels = NULL, ...)
A factor variable
(data.frame) input data.
data.frame
(string) variable to factor.
string
(vector) a character vector of known levels.
vector
other arguments to be passed to factor().
factor()
df <- data.frame(a = c("aa", "a", "aa")) h_factor(df, var = "a") h_factor(df, var = "a", levels = c("aa", "a"))
Run the code above in your browser using DataLab