I am trying to generate a binary matrix where every row in the matrix is 
guaranteed to have at least one 1. Ideally, I would like most rowSums  to be 
equal to 2 or 3 with some 1s and some 4s. But, rowSums cannot be equal to 0.

I can tinker with the vector of probability weights, but in doing so (in the 
way I am doing it) this causes for more rowSums to be equal to 4 than I ideally 
would like, but this never helps to guarantee a rowSum will not be equal to 0. 
I could post-hoc tinker with any rows that are all 0, but seems like that may 
be just inefficient.

Below is sample code, any ideas on how to best tackle this?

Harold



dimMat <- matrix(0, 1000, 4)
for(i in 1:1000){
                dimMat[i, ] <- sample(c(0,1), 4, replace = TRUE, prob = c(.3, 
.7))
                }

table(rowSums(dimMat))

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to