创建一个样本,其中包含R中每个元素中的至少一个

时间:2016-01-05 12:36:39

标签: r random

是否可以使用n元素创建一个大小为x的样本的方法,该元素至少会出现x个元素n >= length(x)

示例:

> n = 10                                         # size of the sample
> vector <- c("a", "b", "c", "d")                # 
> sample(vector, size = n, replace = TRUE)       # 
 [1] "b" "c" "b" "d" "b" "d" "c" "d" "c" "d"     # "a", by chance, don't get selected

我希望每个元素至少出现一次,怎么可能?我应该使用其他功能吗?

输出示例:

> "a" "b" "b" "b" "c" "c" "c" "c" "c" "d" 
> "c" "c" "a" "c" "d" "c" "c" "c" "b" "d" 
> "a" "b" "c" "d" "a" "a" "a" "a" "a" "a" 

0 个答案:

没有答案