Skip to contents

Converts logical vectors and matrices to integer type. Values FALSE, TRUE, and NA are converted to 0, 1, for NA_integer_, respectively.

Usage

logical_to_integer(x)

Arguments

x

(logical vector, matrix, or array)
The logical object to convert to 0/1 integer.

Value

integer vector, matrix, or array with the same dimensions as x.

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