mardi 25 mai 2021

Is there any benefits of set.seed() with slice_sample()

I am using slice_sample() to select some rows from a dataframe. I am doing slice based on 2 loops. The code structure is like the below one

for (j in 1: 10)
{  
  df = dataset // dynamically loading dataset based on the value of j
  for (i in 1:4) {
    
  if(i==1){
    call_function(df, j, 0.3)
  }
  else if(i==2)
  {
    call_function(df, j, 0.4)
  }
  else if(i ==3){
    call_function(df, j, 0.5)
  }
  else{
    call_function(df, j,  0.6)
  }
}
}

The Call_Function() contains the slice_sample().

call_function(df, j, pro){
  slice_sample(df,  prop = pro) }

I have 10 datasets and for every j I am loading different datasets. Here, for every j the function is called 4 times (based on the if-else).

If I use random.seed() to keep the sample (random) index same for the every j it will works?

Actually, I need to keep the sample (random) index same for the every j.




Aucun commentaire:

Enregistrer un commentaire