Random sampling


I have a dataset named "df" of 3 variables and 100 rows. I need to sample 1000 subsamples of 10 rows with "replace = TRUE" form it.

I've tried the code below but it didn't work.

for(i in 1:N){
samp[i] <- sample(df,10,replace=TRUE)


Could you please help me?
Thanks a lot,



df <- data.frame(a = c(1:100),
                 b = c(201:300),
                 c = c(401:500))

sample <- list()

for(i in 1:100){
  sample[[i]] <- dplyr::sample_n(df,10,replace = TRUE)

This should work :slight_smile: let me know

It works! Thanks a lot @ GreyMerchant!

Glad it was of help! :slight_smile: Feel free to mark it as the solution.

Just a side note - always great to have a working bit of code (the code you provided was enough to get going but do try and create a reprex as that just makes it even easier!) FAQ: How to do a minimal reproducible example ( reprex ) for beginners - #2 by andresrcs

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.