R/add_na.R

Defines functions add_na

# An internal function for creating
# missing data.
# For demonstration.
#
#' @noRd

add_na <- function(data, prop = .15, seed = NULL) {
    if (!is.null(seed)) set.seed(seed)
    n <- nrow(data)
    nstar <- nrow(data) * ncol(data)
    i <- sample(nstar, round(nstar * prop))
    i <- lapply(i, function(x) c((x %% n) + 1, ceiling(x / n)))
    for (j in i) {
        data[j[1], j[2]] <- NA
      }
    data
  }

Try the manymome package in your browser

Any scripts or data that you put into this service are public.

manymome documentation built on Oct. 4, 2024, 5:10 p.m.