Convert logical values to 0/1
logical_to_integer.RdConverts logical vectors and matrices to integer type.
Values FALSE, TRUE, and NA are converted to 0, 1, for NA_integer_, respectively.
Details
logical_to_integer() will not drop dimensional attributes (as done by as.integer()).
Examples
#----------------------------------------------------------------------------
# logical_to_integer() examples
#----------------------------------------------------------------------------
library(bkbase)
logical_to_integer(c(TRUE, FALSE, NA))
#> [1] 1 0 NA
logical_to_integer(matrix(c(TRUE, FALSE, TRUE), nrow = 3))
#> [,1]
#> [1,] 1
#> [2,] 0
#> [3,] 1