... 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
retiakov
> Sent: Thursday, November 07, 2013 5:38 AM
> To: r-help@r-project.org
> Subject: [R] all combinations with replacement not ordered
>
> Hello!
>
> I need to obtain all possible combinations with replacement when order is
> not important.
> E.g. I have a populatio
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 list of all that combinations?
I have tried 'expand.grid()' and ma
> Sent: Thursday, April 21, 2011 12:29 PM
> To: r-help@r-project.org
> Subject: [R] all combinations with replacement
>
> 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
>
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
.
.
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
.
.
.
5 0 1
5 1 0
6 0 0
I tried to look at combn() but I could not get this done with it.
Thank you in advance:
Daniel
___
11 matches
Mail list logo