I want to generate an nxm matrix. Suppose its 100x3. I want each row to sum to 1 (so two \"0\"\'s and one \"1\").
sample(c(0,0,1),3)
will
t(apply(t(matrix(rep(c(0,0,1),300),nrow = 3)), 1, function(x) sample(x)))