Description Usage Arguments Value Description Warning Examples
Convert other formats to binary flags.
1 | binarize.vals(x, val0, val1, ignore.case = TRUE)
|
x |
a vector. |
val0, val1 |
the values to convert to 0/1 respectively. |
ignore.case |
if TRUE, conversion will ignore |
as.numeric |
if TRUE, return a numeric vector else return a string. |
A new vector of zeroes and ones.
Flags/indicators are stored in different formats. This function converts two arbitrary values to 0/1. Others will be converted to NA. The default behavior ignores case, e.g. binarize.vals(x, 'Y', 'N') will convert 'Y' to 0 but 'y' to NA. Setting ignore.case = FALSE will first convert all
TRUE is not 'true'! Setting ignore.case = FALSE when converting T/F will not work as desired. The function should catch this by checking is.logical(x).
1 2 3 4 5 6 | x <- c(sample(c('Y', 'N'), 5, replace = T), 'a', 'y', 0, 'n')
print(x)
binarize.vals(x, 'Y', 'N')
x <- c(T, F, T, T, F)
binarize.vals(x, 'T', 'F', ignore.case = F) # wrong
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.