[R] all possible samples

apjaworski@mmm.com apjaworski at mmm.com
Wed Sep 17 18:15:05 CEST 2003


I am not sure if this is the easiest way, but you can do something like
this:

library(gregmisc)
combinations(N, n, x, repeats=TRUE)

where x is an atomic vector of size N.  The only restriction is that the x
vector has to have N unique elements.  The combinations function will
return a matrix with n columns containing the combinations.

The combinations function is defined recursively.  Even for moderate values
of N and n it will either take a long time or bomb out with the "evaluation
is nested too deeply" error.  For example, on my modest machine (PIII 1GHz
with 1/5 Gbyte of memory) it takes almost a minute to evaluate

combinations(30, 6, repeats=TRUE)   (1623160 combinations)

and

combinations(44, 2, repeats=TRUE)   (only 990 combinations)

bombs out.

If you need to work with larger numbers you will probably need a sequential
code.

Hope this helps,

Andy


__________________________________
Andy Jaworski
Engineering Systems Technology Center
3M Center, 518-1-01
St. Paul, MN 55144-1000
-----
E-mail: apjaworski at mmm.com
Tel:  (651) 733-6092
Fax:  (651) 736-3122


|---------+-------------------------------->
|         |           "lamack lamack"      |
|         |           <lamac_k at hotmail.com>|
|         |           Sent by:             |
|         |           r-help-bounces at stat.m|
|         |           ath.ethz.ch          |
|         |                                |
|         |                                |
|         |           09/17/2003 09:52     |
|         |                                |
|---------+-------------------------------->
  >-----------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                             |
  |      To:       R-help at stat.math.ethz.ch                                                                                     |
  |      cc:                                                                                                                    |
  |      Subject:  [R] all possible samples                                                                                     |
  >-----------------------------------------------------------------------------------------------------------------------------|




Dear all, there is an R function that return all possible samples of size
n,
with replacement,  from a vector of length N ?

Best regards

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list