【发布时间】:2016-09-11 10:15:08
【问题描述】:
我陷入了一个数学问题。我想制作一个函数,输出整数“n”可以分为“k”组的所有方式,使得每个组中的“k”至少为 1(k >= 1)。
函数可能类似于:
n_ways <- function(n,k) {...}
我想要一个 dataFrame 作为输出。所以对于:n_ways(5,3)
A B C
1 3 1 1
2 1 3 1
3 1 1 3
4 2 2 1
5 2 1 2
6 1 2 2
解决方案在 dataFrame 中呈现的顺序并不重要。
我寻找像 here 和其他语言的解决方案,如 here 和 here。不幸的是,在此基础上制作适合我的问题的功能并不是那么好,但希望你是。
提前非常感谢!
【问题讨论】:
标签: r math combinations