Open sino30535 opened 4 years ago
Hi,
you can change the order of levels in categorical variables by using relevel()
(?relevel)
A small example using a character variable:
character_var <- c("0 Thoracic", "1 Other")
releveld_var <- relevel(as.factor(character_var), ref ="1 Other")
# or
releveld_2_var <- factor(character_var, levels = c("1 Other", "0 Thoracic"))
df <- data.frame(character_var, releveld_var, releveld_2_var)
tableone::CreateTableOne(factorVars = c("character_var", "releveld_var", "releveld_2_var"), data = df)
Overall
n 2
character_var = 1 Other (%) 1 (50.0)
releveld_var = 0 Thoracic (%) 1 (50.0)
releveld_2_var = 0 Thoracic (%) 1 (50.0)
That's awesome, thank you so much.
Hi,
Love this library and use a lot on my work. I have a question for printing tableone output. For binary categorical variable, is there an argument to choose which label to use? e.g. In surgeon specialty, I have Thoracic or Other value in the variable. Instead of printing SPECIALTY = Other (%), can I manually choose to display SPECIALTY = Thoracic (%)? I don't want to use showAllLevels mode because it would also display too many YES/NO variables that made my tableone unnecessarily long.
Thanks in advance