Hello! I would like to sample 5 % of cases and from 1 to 3 variables within selected cases and set them as NA (MCAR-Missing completely at random). I managed to sample cases and variables, but I don’t know how to set them as NA. R code: N <- 1000 ####number of cases n <- 12 ####number of variables X <- matrix(rnorm(N * n), N, n) ####matrix pMiss <- 0.05 ####percent of missing values idMiss <- sample(1:N, N * pMiss) ####sample cases nMiss <- length(idMiss) m <- 3 ####maximum number of missing variables within selected cases howmanyMiss <- sapply(idMiss, function(x) sample(1:m, 1)) howmanyMiss lapply(howmanyMiss, function(x) sample(1:n, x)) Any suggestion? Thanks, Blaž [[alternative HTML version deleted]]