So I have a data frame consisting of values of 0 and 1. I would like to make a loop that randomly samples 38 of those observations and replaces them with NA. I am successful in doing one iteration, where the original vector observations are replaced with the following one line code:
foo$V2[sample(seq(foo$V2), 38)] <- NA
However, I would like to do this 20 times and have each iteration compiled as separate columns in a single object. Ultimately, I would have a 20 column data frame with each having 191 observations, each with 38 randomly substituted NA's. At the end of the loop, I would like the data frame to be written out as a text file. Thank you for any help in the right direction.
Aucun commentaire:
Enregistrer un commentaire