# NOT RUN {
df <- data.frame(
a = c("y", "n", "y", "y", "n"),
b = c(FALSE, TRUE, FALSE, TRUE, TRUE),
c = c(NA, NA, NA, NA, NA),
d = c(NA, "yes", NA, NA, "yes"),
e = c("y ", "n ", NA, "y ", "n "),
f = c("YES ", "NO ", "NO ", " YES", " NO "),
stringsAsFactors = FALSE
)
df
res <- two_cat_to_logical(df)
stopifnot(identical(res$a, c(TRUE, FALSE, TRUE, TRUE, FALSE)))
stopifnot(identical(res$b, c(FALSE, TRUE, FALSE, TRUE, TRUE)))
two_cat_to_logical(df, ignore_na = TRUE)
# }
Run the code above in your browser using DataLab