That combnWithRepetition (based on combn) can use much
less memory (and time) than the algorithm in prob:::urnsamples.default
with replace=TRUE, ordered=FALSE. Perhaps urnsamples()
could be updated to use combn instead of unique(as.matrix(expand.grid())).
See the urn chapter in Feller vol. 1.
Bi
> combnWithRepetition <- function(n, k) combn(n+k-1, k) - seq(from=0, len=k)
> combnWithRepetition(2, 2)
[,1] [,2] [,3]
[1,]112
[2,]122
> combnWithRepetition(3, 2)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]111223
[2,]123233
ey
Cc: r-help@r-project.org
Subject: Re: [R] Unordered combinations with repetition
You could try expand.grid -- you'd prob need to modify what's beneath
a=c(0,1,2)
b=c(0,1)
c=c(0,1)
y<-list()
y[[1]]<-a
y[[2]]<-b
y[[3]]<-c
expand.grid(y)
This code gives all combinations
On 9
You could try expand.grid -- you'd prob need to modify what's beneath
*a=c(0,1,2)*
*b=c(0,1)*
*c=c(0,1)*
*y<-list()*
*y[[1]]<-a*
*y[[2]]<-b*
*y[[3]]<-c*
*expand.grid(y)*
This code gives all combinations
On 9 June 2015 at 10:11, Thomas Chesney
wrote:
> Does anyone know of a function tha
Does anyone know of a function that will return all unordered combinations of n
elements from a list with repetition?
The combs function in caTools will do this without repetition:
combs(1:2, 2)
[,1] [,2]
[1,]12
What I'd like is:
1 1
1 2
2 2
Thank you,
Thomas Chesney
This me
5 matches
Mail list logo