Skip to content
Prev 359379 / 398502 Next

sample within a loop

I would change strategies.

Create a new variable, say,
  num.in.grp <- rep(1:12, 4)

Then sample from 1:12, and add appropriate amounts so that they become row
numbers within the four sets of 12 rows
  ctrls <- ssample(1:12, 4, replace=TRUE) + c(0,12,24,36)

Now that we have four random row numbers, assign entry appropriately
  entry <- rep('TEST', 48)
  entry[ctrls] <- 'CONTROL'

The above is not tested, and makes several assumptions, particularly that
the data frame is sorted by groups and that there are four groups of 12
each. Thus it is does not generalize, not without some work.

-Don