Counting the number of columns in logical matrix in R
<p>I have a matrix like this in R:</p>

<pre><code>matrix =
      1     2     3     4    5     6     7    8     9   10
X3  TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE TRUE
X2  TRUE FALSE  TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE
X1 FALSE FALSE  TRUE FALSE TRUE  TRUE FALSE TRUE FALSE TRUE
</code></pre>

<p>and I need to know how many columns have their 3 values in TRUE. The solution I'm looking for needs to be generic enough so it can be applied to any possible dimensions of the matrix. I tried</p>

<pre><code>length(which(apply(matrix, 2, function(x) x[1] &amp; x[2] &amp; x[3])))
</code></pre>

<p>and that worked but it is not generic.</p>

<p>Can you help me?</p>

<p>Thanks!</p>

<p>Mariano.</p>