Reorder PARAM and PARAMCD Levels Simultaneously

reorder_levels_params(df, paramcd_levels)

Arguments

df

data.frame with PARAM and PARAMCD variables

paramcd_levels

ordered levels of PARAMCD

Examples

df <- data.frame(PARAMCD = factor(c("A", "B", "C")), PARAM = factor(paste("letter", LETTERS[1:3])))

str(reorder_levels_params(df, paramcd_levels = c("B", "A", "C")))
#> 'data.frame':	3 obs. of  2 variables:
#>  $ PARAMCD: Factor w/ 3 levels "B","A","C": 1 2 3
#>  $ PARAM  : Factor w/ 3 levels "letter B","letter A",..: 1 2 3
str(reorder_levels_params(df, paramcd_levels = c("B", "A")))
#> 'data.frame':	3 obs. of  2 variables:
#>  $ PARAMCD: Factor w/ 3 levels "B","A","C": 1 2 3
#>  $ PARAM  : Factor w/ 3 levels "letter B","letter A",..: 1 2 3