根据条件对 n 个对象进行 x 次采样

Sample n objects x times according to a condition

我想从总共 26 个字母集中采样 6 个字母 n 次,以便每个字母在所有 n 次中准确采样 3 次。我如何在 R 或 python 中写这个?

编辑:我错过了一个关键标准,每组 6 个字母应该是唯一的。所以每组6个字母应该不放回地采样

根据您的条件,您最多可以有 13 个样本,即 26 * 3 / 6 = 13。这是获取它们的一种方法 -

set.seed(2)
m <- matrix(sample(rep(letters, 3)), nrow = 6)
m
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,] "o"  "j"  "y"  "a"  "s"  "a"  "j"  "g"  "p"  "x"   "x"   "p"   "y"  
[2,] "c"  "h"  "l"  "e"  "l"  "z"  "m"  "f"  "x"  "n"   "d"   "v"   "o"  
[3,] "r"  "g"  "z"  "m"  "h"  "p"  "q"  "v"  "v"  "a"   "e"   "c"   "o"  
[4,] "m"  "l"  "b"  "w"  "k"  "n"  "f"  "s"  "b"  "u"   "d"   "h"   "y"  
[5,] "r"  "u"  "i"  "u"  "w"  "e"  "t"  "f"  "r"  "w"   "t"   "t"   "z"  
[6,] "q"  "q"  "n"  "i"  "g"  "s"  "k"  "k"  "c"  "j"   "i"   "d"   "b"  

table(m)
m
a b c d e f g h i j k l m n o p q r s t u v w x y z 
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3