for testing purposes I need to add missing values to a data frame which has no missing values, how can I add 10% random NA
s to my data frame:
dat <- data.frame(v1=rnorm(20),v2=rnorm(20),v3=rnorm(20))
my idea was something like:
a <- sample(1:nrow(dat),3,replace=F)
b <- sample(1:ncol(dat),2,replace=F)
dat[a,b] <- NA
but this is not random enough. thanks.