Make a binary matrix out of a weighted matrix

to_binary_matrix(mat, min)

Arguments

mat

a numeric matrix

min

a threshold. All values in mat of at least this minimum value will become 1, all values smaller than this minimum will become 0.

Value

the dichotomized matrix

Details

If a cell has value smaller than a minimum value, the cell becomes 0. If the cell has a value of at least the minimum value, it becomes 1. The procedure will work for any matrix, not necessarily a square one.

Examples

M <- matrix(round(runif(20),1), ncol = 4)
to_binary_matrix(M, min = .45)
#>      [,1] [,2] [,3] [,4]
#> [1,]    0    0    1    0
#> [2,]    1    1    1    1
#> [3,]    0    0    0    0
#> [4,]    0    1    0    0
#> [5,]    0    1    1    1