combn(utils)
combn()所属R语言包:utils
Generate All Combinations of n Elements, Taken m at a Time
在同一时间产生n个元素,两者米的所有组合
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Generate all combinations of the elements of x taken m at a time. If x is a positive integer, returns all combinations of the elements of seq(x) taken m at a time. If argument FUN is not NULL, applies a function given by the argument to each point. If simplify is FALSE, returns a list; otherwise returns an array, typically a matrix. ... are passed unchanged to the FUN function, if specified.
生成所有的元素组合x采取m一次。 x如果是一个正整数,返回所有的元素组合seq(x)取m一次。如果参数FUN是NULL,适用于由参数给每个点的功能。如果简化为FALSE,返回一个列表,否则返回array,通常是matrix。 ...FUN函数传递不变,如果指定。
用法----------Usage----------
combn(x, m, FUN = NULL, simplify = TRUE, ...)
参数----------Arguments----------
参数:x
vector source for combinations, or integer n for x <- seq_len(n).
矢量源组合,或整数nx <- seq_len(n)。
参数:m
number of elements to choose.
选择的元素数目。
参数:FUN
function to be applied to each combination; default NULL means the identity, i.e., to return the combination (vector of length m).
功能被应用到每个组合;默认的NULL意味着身份,即返回的组合(向量长度m)。
参数:simplify
logical indicating if the result should be simplified to an array (typically a matrix); if FALSE, the function returns a list. Note that when simplify = TRUE as by default, the dimension of the result is simply determined from FUN(<VAR>1st combination</VAR>) (for efficiency reasons). This will badly fail if FUN(u) is not of constant length.
逻辑表示如果结果应该被简化为一个array(通常是matrix);如果为FALSE,函数返回一个list。请注意,当simplify = TRUE默认情况下,最终结果的维度是简单地从FUN(<VAR>1st combination</VAR>)(出于效率的考虑)确定。 FUN(u)如果不固定长度,这将严重失败。
参数:...
optionally, further arguments to FUN.
可选FUN进一步论据。
值----------Value----------
a list or array, see the simplify argument above. In the latter case, the identity dim(combn(n,m)) == c(m, choose(n,m)) holds.
list或array,simplify参数以上。在后一种情况,身份dim(combn(n,m)) == c(m, choose(n,m))持有。
作者(S)----------Author(s)----------
Scott Chasalow wrote the original in 1994 for S;
R package <span class="pkg">combinat</span> and documentation by Vince Carey
<a href="mailto:stvjc@channing.harvard.edu">stvjc@channing.harvard.edu</a>;
small changes by the R core team, notably to return an array in all
cases of <code>simplify = TRUE</code>, e.g., for <code>combn(5,5)</code>.
参考文献----------References----------
Combinatorial Algorithms for Computers and Calculators; Academic Press, NY.
参见----------See Also----------
choose for fast computation of the number of combinations. expand.grid for creating a data frame from all combinations of factors or vectors.
choose快速组合的数量计算。 expand.grid创建一个因素或向量组合的数据框。
举例----------Examples----------
combn(letters[1:4], 2)
(m <- combn(10, 5, min)) # minimum value in each combination[在每个组合的最低值]
mm <- combn(15, 6, function(x) matrix(x, 2,3))
stopifnot(round(choose(10,5)) == length(m),
c(2,3, round(choose(15,6))) == dim(mm))
## Different way of encoding points:[#编码点的不同的方式:]
combn(c(1,1,1,1,2,2,2,3,3,4), 3, tabulate, nbins = 4)
## Compute support points and (scaled) probabilities for a[#计算(规模)的概率为支撑点]
## Multivariate-Hypergeometric(n = 3, N = c(4,3,2,1)) p.f.:[#多元超几何(N = 3,N = C(4,3,2,1))PF:]
# table.mat(t(combn(c(1,1,1,1,2,2,2,3,3,4), 3, tabulate,nbins=4)))[table.mat(T(combn(C(1,1,1,1,2,2,2,3,3,4),3,制表,nbins = 4)))]
## Assuring the identity[#确保身份]
for(n in 1:7)
for(m in 0:n) stopifnot(is.array(cc <- combn(n, m)),
dim(cc) == c(m, choose(n,m)))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|