This works, but there might be a better way: misscols<-lapply(howmanyMiss, function(x) sample(1:n, x))
for (i in 1:nMiss){ for (j in misscols[[i]]){ X[idMiss[i],j]<-NA } } ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.