[R] Combination with repetition

Jose Luis Aznarte M. jlaznarte at decsai.ugr.es
Fri Aug 15 18:27:24 CEST 2008


   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)

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



More information about the R-help mailing list