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