Sampling small data frame from a big dataframe

后端 未结 2 1452
野趣味
野趣味 2021-01-20 06:15

I am trying to sample a data frame from a given data frame such that there are enough samples from each of the levels of a variable. This can be achieved by separating the d

2条回答
  •  萌比男神i
    2021-01-20 06:57

    It would seem that if you want to sample a category that has less than 20 rows, you'd need replace=TRUE...

    This might do the trick:

    ddply(data1,'a',function(x) x[sample.int(NROW(x),20,replace=TRUE),])
    

提交回复
热议问题