iginal Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Doran, Harold
Sent: Wednesday, April 9, 2014 3:56 PM
To: r-help@r-project.org
Subject: [R] Generate Binary Matrix
I am trying to generate a binary matrix where every row in the
matrix is guarantee
A bit kludgey but how about:
dimMat <- matrix(0, 1000, 4)
for(i in 1:1000){
while(sum(dimMat[i, ] <- sample(c(0,1), 4, replace = TRUE, prob = c(.3, .7)))==0)
dimMat[i, ] <- sample(c(0,1), 4, replace = TRUE, prob = c(.3, .7))
}
table(rowSums(dimMat))
Clint BowmanINTERNET:
Doran, Harold air.org> writes:
> I am trying to generate a binary matrix where
row
in the matrix is guaranteed to have at
least one 1.
> Ideally, I would like most rowSums to be equal
2 or 3
with some 1s and some 4s. But,
rowSums cannot be equal
> to 0.
>
> I can tinker with the vector o
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
4 matches
Mail list logo