如何从 R 中变量的每个级别抽样相同数量的单位?

How to sample equal number of units from each level of a variable in R?

R 中是否有任何函数可以 select 变量的每个级别的单位数​​相等?例如,我有一个数据集,其中包含一个名为 "taste" 的变量,变量口味分为三个级别,例如 "bad"、"normal" 和 "good"。现在我想要 select 一个样本,它从口味变量的每个级别抽取相同数量的单位。我如何在 R 中 select 这样的样本?

我们可以用 repsample

sample(rep(unique(data$taste), each = 25))