I am trying to program a ranked set sampling using R. There are 2*n^2 items and I want to randomly divide them into two equal sized groups with n^2 items in each group. Then I want to use a Ranked Set Sampling from each of these groups to form n RSS blocks with n items in each RSS block.
What I was trying is shown below:
n<-4
id<-1:(2*n^2)
s1<-sample(id,n^2)
s2<-id[-s1]
block<-rep(1:(2*n),each=n)
d<-data.frame(block)
Now I want a column in my data frame named rss that will show which id’s are selected in a particular RSS block.
I am not good at R. I was trying this:
for(i in 1:n){
d$rss<-ifelse(d$block==i,sample(s1,n),0)
#s1<-s1[-which(s1==d$rss)]
}
for(i in 1:n){
d$rss<-ifelse(d$block==i,sample(s2,n),0)
#s2<-s2[-which(s2==d$rss)]
}
which I know is very wrong! Can anyone help?
You should give an example of the output you want, but giving it my best guess:
Or, in a more organized manner: