Functions/MVgen.R

# Amputation of the initial (simulated) dataset
# dataset = dataset to be amputed
# prop_NA = desired proportion of missing values in the amputed dataset

MVgen <- function(dataset, prop_NA){
  data_NA <- dataset
  n_NA <- prop_NA * prod(dim(dataset))
  row_NA <- sample(1:nrow(dataset), n_NA, replace = TRUE)
  col_NA <- sample(1:ncol(dataset), n_NA, replace = TRUE)
  for (i in 1:n_NA) data_NA[row_NA[i], col_NA[i]] <- NA
  return(data_NA)
}
mariechion/mi4p documentation built on Oct. 3, 2024, 4:50 a.m.