How can I find out how many rows of a matrix satisfy a rather complicated criterion (in R)?

Posted by Brani on Stack Overflow See other posts from Stack Overflow or by Brani
Published on 2010-05-22T20:18:44Z Indexed on 2010/05/22 20:20 UTC
Read the original article Hit count: 235

Filed under:
|
|
|

As an example, here is a way to get a matrix of all possible outcomes of rolling 4 (fair) dice.

z <- as.matrix(expand.grid(c(1:6),c(1:6),c(1:6),c(1:6)))

As you may already have understood, I'm trying to work out a question that was closed, though, in my opinion, it's a challenging one. I used counting techniques to solve it (I mean by hand) and I finaly arrived to a number of outcomes, with a sum of subset being 5, equal to 1083 out of 1296. That result is consistent with the answers provided to that question, before it was closed. I was wondering how could that subset of outcomes (say z1, where dim(z1) = [1083,4] ) be generated using R. Do you have any ideas?

Thank you.

© Stack Overflow or respective owner

Related posts about r

    Related posts about indexing