How to program a Ranked Set Sampling in R?

#1
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:

Code:
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:

Code:
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?
 
#2
I think this might be what you want:
Code:
d <- transform(d,rss = ifelse(d[,"block"]<=n, sample(s1), sample(s2)))
You can also organize it a little better like this:
Code:
d <- transform(d,block.id = rep(1:n))
d <- transform(d,rss = ifelse(d[,"block"]<=n, sample(s1), sample(s2)))
d <- dcast(d,block ~ block.id, value = rss)