我希望在R中为1000个客户生成一个人口,这些客户可以从10到1000落入一个值桶。客户在10个区间内陷入困境。例如,客户A可能属于价值桶10,20,30 .... 1000。它们是互斥的,因此它们只能在给定方案中落入一个桶中。我想要一个包含1000个客户的所有可能方案的填充列表。这有可能吗?因为排列相当庞大。感谢我能得到的任何帮助。
答案 0 :(得分:0)
N = 100:100个桶数 1000位客户
要生成一个可能的排列使用样本:
sample(100,1000,replace=T)
要生成100种可能的排列,请使用replicate
replicate(n=100,sample(100,1000,replace=T))
您可以使用gtools包生成所有可能的排列
library(gtools)
r <- permutations(100,1000,repeats.allowed=T)
但结果矩阵将是巨大的......
有4个客户和2个存储桶的示例:
permutations(2,4,repeats.allowed = T)
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
[2,] 1 1 1 2
[3,] 1 1 2 1
[4,] 1 1 2 2
[5,] 1 2 1 1
[6,] 1 2 1 2
[7,] 1 2 2 1
[8,] 1 2 2 2
[9,] 2 1 1 1
[10,] 2 1 1 2
[11,] 2 1 2 1
[12,] 2 1 2 2
[13,] 2 2 1 1
[14,] 2 2 1 2
[15,] 2 2 2 1
[16,] 2 2 2 2
答案 1 :(得分:0)
这是可能的,看起来很简单。
set.seed(2317) # make the results reproducible
bucket <- seq.int(10L, 1000L, by = 10L)
sample(bucket, 1000, TRUE)