Re: [R] Listing all possible samples of size n form a population

From: Ted Harding <Ted.Harding_at_nessie.mcc.ac.uk>
Date: Fri 09 Dec 2005 - 02:07:40 EST


On 08-Dec-05 Ales Ziberna wrote:
> Dear useRs!
>
> I would like to list all possible samples of size n form a
> population of size N. Obviously, N must be small (up to 20??)
> for this to be possible.
>
> For example, let say that N = 3 and n = 2. Therefore, we can
> say we have units 1, 2 and 3. I believe all possible samples
> are : {1,2},{2,3} and {1,3}.
>
> I would like to emphasize that I am not looking for the number
> of different samples, but a list of all possible samples.

Install package "combinat" and use the function 'combn' therein:

> library(combinat)
> ?combn

> combn((1:3),2)

     [,1] [,2] [,3]
[1,] 1 1 2
[2,] 2 3 3

> combn((1:5),2)

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    1    2    2    2    3    3     4
[2,]    2    3    4    5    3    4    5    4    5     5


> combn((1:5),3)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 1 1 1 1 1 2 2 2 3 [2,] 2 2 2 3 3 4 3 3 4 4 [3,] 3 4 5 4 5 5 4 5 5 5

and so on ...

Best wishes,
Ted.



E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 08-Dec-05                                       Time: 15:07:37
------------------------------ XFMail ------------------------------

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Dec 09 02:21:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:34 EST