char2factor | R Documentation |
Convert character variable to a factor based off it's numeric variable counterpart.
char2factor(df, c_var, n_var)
df |
data frame. |
c_var |
character variable within the data frame. |
n_var |
numeric variable counter part within the data frame to control the levels. |
A factor.
df <- tibble::tribble(
~TRT01P, ~TRT01PN,
"Placebo", 1,
"Low Dose", 2,
"High Dose", 3
)
# alphabetical order
dplyr::arrange(df, TRT01P)
# change to factor with char2factor
df$TRT01P <- char2factor(df, "TRT01P", "TRT01PN")
# factor order
dplyr::arrange(df, TRT01P)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.