fct_yesno(c("No", "Yes")) #levels are in order
set.seed(42)
N=6
x = tibble(
a=sample(c("Yes", "No"), size=N, replace=TRUE),
b=sample(c("Oui", "Non"), size=N, replace=TRUE),
c=sample(0:1, size=N, replace=TRUE),
d=sample(c(TRUE, FALSE), size=N, replace=TRUE),
e=sample(c("1-Yes", "0-No"), size=N, replace=TRUE),
y=sample(c("aaa", "bbb", "ccc"), size=N, replace=TRUE),
z=1:N,
)
x
#y and z are left untouched (or throw an error if fail=TRUE)
sapply(x, fct_yesno, fail=FALSE)
# as "1-Yes" is not in `input`, x$e is untouched/fails if strict=TRUE
fct_yesno(x$e)
fct_yesno(x$e, strict=TRUE, fail=FALSE)
fct_yesno(x$e, output=c("Ja", "Nein"))
Run the code above in your browser using DataLab