I'm interested in taking random samples from an existing dataset (10000 rows and 114 columns) with increasing sizes (from 194 to 236: 194, 208, 222, 236), and with replacement.
Until now, I was trying to do this. However, I can't find a way to input the different sizes (that's why it fails in the x definition).
# A small portion of the dataset
dataset <- data.frame(ID = c("model0001", "model0002", "model0003", "model0004", "model0005",
"model0006", "model0007", "model0008", "model0009", "model0010"),
IL_NA = 1:10, PROD = 11:20, INJ = 21:30)
# As mentioned, my real sizes are -> seq(194,236,by=14) to get samples sizes of 194, 208, 222, 236; for this example:
sizes <- seq(1,8,by=2)
x <- rep_sample_n(candidate_wells, size=sizes, replace=T, reps=4)
sample_set <- lapply(x, function(i) dataset[sample(nrow(dataset), i), ])
Any help will be appreciated. Thanks!
CodePudding user response:
You were really close. I don't know where rep_sample_n
is from, but if you skip that line everything else looks right:
sizes <- seq(1, 8, by = 2)
sample_set <- lapply(sizes, function(i) dataset[sample(nrow(dataset), i), ])