View source: R/convert_to_logical.R
convert_to_logical | R Documentation |
This is particularly useful for binary variables that have been encoded with e.g. Yes and No as options. Variable labels are retained, which may or may not make sense, depending on the variable
convert_to_logical(
data,
vars,
true = "Yes",
replace = TRUE,
append = "_logical"
)
data |
dataframe |
vars |
character string of variables to convert |
true |
value which should become |
replace |
Replace the indicated variables |
append |
text to append to new variables (when |
data
with modified variables, potentially with additional variables
(if replace = TRUE
)
data(mtcars)
convert_to_logical(mtcars, "am", 1)
convert_to_logical(mtcars, c("am", "vs"), 1)
convert_to_logical(mtcars, c("am", "vs"), 1, FALSE)
convert_to_logical(mtcars, c("am", "vs"), 1, FALSE, "_lgl")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.