| base_match | R Documentation |
A base-R approximation of case_match() from 'dplyr'. Unlike case_match(), base_when() returns a factor. The levels will be ordered according to the order included in ... (see below).
base_match(original_variable, ..., as_factor = TRUE, string_for_na = "")
original_variable |
the original variable |
... |
the codebook, specified as a named vector, 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 country
nhanes<-nhanes |> transform(
country=base_match(dmdborn4,'USA'=1,'Other'=2)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.