powered by
Turns Yes/No variables into 1/0 integers
onezero(x)
an integer vector
a character vector
The input is forced to lowercase and only the first character, the "y" or "n", is used to map to the 1/0 integer values. The function allows for "1" and "0" to be in the character vector as well.
flag <- c("Y", "No", "NO", "no", "n", "YES", "Yes", "yEs", "1", "0") onezero(flag)
Run the code above in your browser using DataLab