samedi 4 mai 2019

I need to sample n groups of n random rows from df in R

I want to iterate n times a function that draws n rows at random from a dataframe.Since the groups consist each of 785 rows, the function is this:

randomSample = function(merged_df_1,n) { 
  return (merged_df_1[sample(nrow(merged_df_1), 785),])
}


To iterate this function 10 times, I tried this code

n=10
lapply(rep(1, n), randomSample)

But I get the following error message "Error in sample.int(length(x), size, replace, prob) : invalid first argument"




Aucun commentaire:

Enregistrer un commentaire