[R] Combination with repetition

Charles C. Berry cberry at tajo.ucsd.edu
Fri Aug 15 21:35:00 CEST 2008


On Fri, 15 Aug 2008, Jose Luis Aznarte M. wrote:

>  Hi there! I can't find any information about creating combinations with 
> repetitions in R. The function combn() does create combinations, but 
> _without_ repetitions.
>    Here is what I need to do:
>
> svIter <- 1000
> xx <- matrix(rnorm(m*n), c(m, n))
> sequence <- seq(range(xx)[1], range(xx)[2], length.out = svIter^(1/q))
> expand.grid(secuence, secuence, .../q times/..., secuence)

See

 	?do.call

do.call( expand.grid, rep( list(sequence), q ) )

HTH,

Chuck

p.s. Using function names as object names (e.g. 'q') is considered bad 
practice

>
> That is, I need a grid which covers a q-dimensional space with range 
> range(xx) for each dimension, and a total number of points close to svIter. 
> My problem could be solved by writting the expand.grid call at runtime, but I 
> think that is not very elegant and, overall, I don't know how to do that. If 
> combn() accepted repetitions, it'd be solved also.
>    Any help will be greatly appreciated.
>    Bests,
>
> --                                                      --
> Jose Luis Aznarte M.       http://decsai.ugr.es/~jlaznarte
> Department of Computer Science and Artificial Intelligence
> Universidad de Granada           Tel. +34 - 958 - 24 04 67
> GRANADA (Spain)                  Fax: +34 - 958 - 24 00 79
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list