#' Split a list of cells
#'
#' This is done my doublication the cells and applying possible mutations to
#' them.
#'
#' @param cell cells matrix.
#' @inheritParams gland_create
#'
#' @return list of cells.
cell_split <- function(cell, change) {
mutation(weave_matrix(cell, cell), change = change)
}
#' Randomly modify a cell.
#'
#' This function takes a cell a flips some of values by chance.
#'
#' @inheritParams cell_split
#' @return A cells matrix.
#'
#' @importFrom stats runif rbinom
mutation <- function(cell, change) {
zeroes <- which(cell == 0)
ones <- which(cell == 1)
zeroes_length <- length(zeroes)
ones_length <- length(ones)
draws_zeroes <- rbinom(1, zeroes_length, change[1])
if (draws_zeroes != 0) {
cell[zeroes[ceiling(runif(draws_zeroes, max = zeroes_length))]] <- 1
}
draws_ones <- rbinom(1, ones_length, change[2])
if (draws_ones != 0) {
cell[ones[ceiling(runif(draws_ones, max = ones_length))]] <- 0
}
cell
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.