Last active
August 29, 2015 14:07
-
-
Save njtierney/0c30459844ce7d2d2962 to your computer and use it in GitHub Desktop.
create MCAR data (from package `mi`).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mi:::.create.missing | |
function (data, pct.mis = 10) | |
{ | |
n <- nrow(data) | |
J <- ncol(data) | |
if (length(pct.mis) == 1) { | |
n.mis <- rep((n * (pct.mis/100)), J) | |
} | |
else { | |
if (length(pct.mis) < J) | |
stop("The length of missing does not equal to the column of the data") | |
n.mis <- n * (pct.mis/100) | |
} | |
for (i in 1:ncol(data)) { | |
if (n.mis[i] == 0) { | |
data[, i] <- data[, i] | |
} | |
else { | |
data[sample(1:n, n.mis[i], replace = FALSE), i] <- NA | |
} | |
} | |
return(as.data.frame(data)) | |
} | |
<environment: namespace:mi> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment