| ref_lvl {sjmisc} | R Documentation |
Changes the reference level of numeric factor. See 'Details'.
ref_lvl(x, ..., lvl = NULL)
x |
A vector or data frame. |
... |
Optional, unquoted names of variables that should be selected for
further processing. Required, if |
lvl |
Numeric, the new reference level. |
Unlike relevel, this function a) only accepts
numeric factors and b) changes the reference level by recoding
the factor's values using the rec function. Hence,
all values from lowest up to the reference level indicated by
lvl are recoded, with lvl starting as lowest
factor value. See 'Examples'.
x with new reference level. If x
is a data frame, the complete data frame x will be returned,
where variables specified in ... will be re-leveled;
if ... is not specified, applies to all variables in the
data frame.
to_factor to convert numeric vectors into factors;
rec to recode variables.
data(efc) x <- to_factor(efc$e42dep) str(x) frq(x) x <- ref_lvl(x, lvl = 3) str(x) frq(x) library(dplyr) dat <- efc %>% select(c82cop1, c83cop2, c84cop3) %>% to_factor() frq(dat) ref_lvl(dat, c82cop1, c83cop2, lvl = 2) %>% frq()