... and actually, since u can be assumed to be of the form shown,
v <-do.call(expand.grid, split(rep(u,len),rep(u,e=len)))
should do.
-- Bert
On Thu, Nov 7, 2013 at 10:06 AM, Bert Gunter wrote:
> Well, you can create the expand.grid data frame programmatically via:
>
> u <- 1:3
> len <- lengt
Well, you can create the expand.grid data frame programmatically via:
u <- 1:3
len <- length(u)
v <-do.call(expand.grid, split(rep(u,len),rep(seq_len(len),e=len)))
And then you can use unique.array to get the unique rows after the sort:
unique(t(apply(v,1,sort)))
However, I agree with your sent
On 07-Nov-2013 13:38:29 Konstantin Tretiakov wrote:
> Hello!
>
> I need to obtain all possible combinations with replacement when
> order is not important.
> E.g. I have a population x{1,2,3}.
> So I can get (choose(3+3-1,3)=) 10 combinations from this population
> with 'size=3'.
> How can I get a
Is this what you want?
f <- function (x, m) combn(x + m - 1, m) - seq_len(m) + 1
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Konstantin Tretiakov
> Sent: Thurs
Does the following do what you want? It should
generate all the (unordered) NPart-partitions of Sum
by mapping the output of combn(Sum+NParts-1,NParts-1).
f <- function (Sum, NParts)
{
cm <- combn(Sum + NParts - 1, NParts - 1)
cm <- rbind(cm, Sum + NParts)
if (NParts > 1) {
On Thu, Apr 21, 2011 at 12:52:34PM -0700, Kehl Dániel wrote:
> Thank you.
> I only need those where the rowsum = n.
> I could choose those with code, but I dont think it is efficient that way.
Efficiency of using expand.grid() may be improved, if expand.grid()
is used only to k-1 columns, then the
Hi Kehl,
How large are n and k in your case? Using Dimitris' approach and I got the
following timings for 1000 replicates:
# function based on Dimitri's reply
foo <- function(n, k){
r <- expand.grid(rep(list(0:n), k))
subset(r, rowSums(r) == n)
}
# a second try
foo2 <- function(n
Thank you.
I only need those where the rowsum = n.
I could choose those with code, but I dont think it is efficient that way.
daniel
2011-04-21 12:33 keltezéssel, Dimitris Rizopoulos írta:
expand.grid(rep(list(0:6), 3))
__
R-help@r-project.org mai
probably expand.grid(), e.g.,
expand.grid(rep(list(0:6), 3))
I hope it helps.
Best,
Dimitris
On 4/21/2011 9:28 PM, Kehl Dániel wrote:
Dear all,
is there an easy way to get all possible combinations (?) with replacement.
If n=6, k=3, i want something like
0 0 6
0 5 1
0 4 2
0 3 3
0 2 4
.
.
9 matches
Mail list logo