我如何找到所有可能的离散值和出现

oax*_*att 2 r

鉴于: yi <- c(1,2,4,4,7,7,7,8)

现在从上面的8个单元中抽取4个单元,使用简单的随机抽样进行更换.

我想找到所有(8选4 =)70组合的所有可能的离散值,并且每个离散值的数量都会出现.

例如:
t1 =(1,2,4,4)= 11,只发生一次
t2 ...

flo*_*del 7

你可以使用combinat::combn:

library(combinat)
all.poss <- t(combn(yi, 4))

dim(all.poss)
# [1] 70 4
table(rowSums(all.poss))
# 11 14 15 16 17 18 19 20 21 22 23 24 25 26 29 
#  1  6  2  3  7  4  6 12  6  4  7  3  2  6  1 
Run Code Online (Sandbox Code Playgroud)

  • 你是否建议`combinat :: combn`与`utils :: combn`不同,即实际上需要加载pkg :: combinat? (2认同)