[R] Combination with repetition

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Fri Aug 15 21:30:56 CEST 2008


you could use something like the following:

expand.grid(rep(list(1:3), 4))


I hope it helps.

Best,
Dimitris


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)
> 
> 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.
> 
> 

-- 
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://perswww.kuleuven.be/dimitris_rizopoulos/



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list