Skip to content
Prev 213535 / 398500 Next

Randomly sampling subsets of dataframe variable

On Mar 12, 2010, at 3:06 PM, Hosack, Michael wrote:

            
> replicate(26,sample(1:5, 2))
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [, 
13] [,14] [,15] [,16] [,17]
[1,]    4    1    3    2    3    1    3    5    1     1     2      
4     2     5     1     1     5
[2,]    1    3    4    1    2    3    4    3    3     2     4      
5     1     2     3     5     1
      [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
[1,]     2     4     5     4     5     3     3     4     4
[2,]     4     2     2     1     2     1     1     1     2

 > replicate(26,sample(1:5, 2))[,1]
[1] 1 4

--
David Winsemius, MD
West Hartford, CT