| base_when | R Documentation |
A base-R approximation of case_when() from 'dplyr'. Unlike case_when(), base_when() returns a factor. The levels will be ordered according to the order included in ... (see below).
base_when(..., as_factor = TRUE, string_for_na = "")
... |
conditions for defining the replacement values, specified as a named list, with each element in |
as_factor |
logical, controlling whether the function should return a factor |
string_for_na |
string value that will be converted to NA |
a factor
# load data
data(nhanes)
# define cholesterol
nhanes<-nhanes |>
transform(
cholesterol=base_when(
'Desirable' = (lbxtc<200),
'Borderline high' = (lbxtc>=200)&(lbxtc<240),
'High' = (lbxtc>=240)
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.