#' Dichotomize a matrix
#'
#' Make a binary matrix out of a weighted matrix
#'
#' 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.
#'
#' @param mat a numeric matrix
#' @param min a threshold. All values in \code{mat} of at least this minimum value
#' will become 1, all values smaller than this minimum will become 0.
#' @return the dichotomized matrix
#' @export dichotMat
#' @examples
#' M <- matrix(round(runif(20),1), ncol = 4)
#' dichotMat(M, min = .45)
dichotMat <- function(mat, min) {
mat <- ifelse(mat < min, 0, 1)
return(mat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.