Skip to content
Prev 276629 / 398506 Next

Sampling with conditions

Sarah,

Does something like this do what you want?

n <- matrix(0,nrow=5, ncol=10)
repeat{
  c1 <- sample(0:10, 4, replace=TRUE)
  if(sum(c1) <= 10) break
}
n[,1] <- c(c1,10-sum(c1))
n


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA