Skip to content
Prev 303798 / 398513 Next

Iterative sampling with restrictions

David,

I would collect the sample waves into a data.frame.  I am sure someone will be able to help you with a more general and/or efficient solution, but to get you started I have provided one possible solution to your 60 unit 3 wave example
 
#create data.frame with IDs
df <- data.frame(id=1:60)

#create first sample wave
df$wave1 <- sample(rep(1:3,20))

#reorder df and create second wave sample
df <- df[order(df$wave1),]
df$wave2 <-  c(sample(rep(c(2,3),10)),
               sample(rep(c(1,3),10)),sample(rep(c(1,2),10)))

#now use set diff to create 3rd wave
for(i in 1:60) df[i,'wave3'] <- unlist(setdiff(1:3,df[i,2:3]))

df


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA