binary2factor | R Documentation |
Convert binary data to factors based on column name
binary2factor(.data, ...)
.data |
(data.frame) A data frame or data frame extension (e.g. a tibble) |
... |
Name-value pairs. The names of columns to be transformed |
(data.frame) An object of the same type as .data
df <- data.frame(
a = c(1, 0, NA, 1, 0),
b = c("y", "n", NA, "Y", "n"),
c = c("yes", "no", NA, "Yes", "No"),
d = c(TRUE, FALSE, NA, TRUE, FALSE),
e = c(1, 2, 3, 4, 5)
)
binary2factor(df, a, b:d)
df %>%
binary2factor(-e)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.