[R] Sampling procedure

David Winsemius dwinsemius at comcast.net
Thu Oct 15 16:54:33 CEST 2009


On Oct 15, 2009, at 10:19 AM, Marcio Resende wrote:

>
> I would like to divide a vector in 9 groups in a way that each  
> number is
> present in only one group.
> In a vector of 783 I would like to divide in 9 different groups of 87
>
> Example <- matrix(c(1:783),ncol = 1)


 > Example <- matrix(c(1:783),ncol = 1)
 > Grp1 <- sample(Example, 87, replace=FALSE)
 > Grp2 <- sample(Example[-Grp1], 87, replace=FALSE)
 > Grp3 <- sample(Example[-c(Grp1, Grp2)], 87, replace=FALSE)
# lather, rinse , repeat


> s1 <- as.matrix(sample(Example,87, re = FALSE))
> Example <- Example[-s1]
> s2 <- as.matrix(sample(Example,87, re = FALSE))
> #however I don´t know how to remove the second group from the  
> "Example" to
> continue sampling.
>

#Don't mess up the original

> There is probably an easy and faster way to do this.
> Could anybody help me?
> Thanks
-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list