[R] Drawing sample

David Winsemius dwinsemius at comcast.net
Sun Jan 29 18:15:16 CET 2012


On Jan 29, 2012, at 11:21 AM, Ron Michael wrote:

> Dear all, here I need to draw all possible samples of size 2, from a  
> population, which is characterized by c(1,4,56, 3).

 > combn(c(1,4,56, 3), 2)  # an enumeration of possible tuples
      [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    1    1    4    4   56
[2,]    4   56    3   56    3    3


> Sampling will be done with replacement. Is there any direct R  
> function to faciliate this darwing?

Here is an implementation of such a sample from that matrix.

 > combn(c(1,4,56, 3), 2)[ , sample(1:6, 10, replace=TRUE)]
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]   56    4    4    1    4    1    1    1    1     1
[2,]    3    3   56    4    3    4    4    3   56     3


-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list