title: How to identify which columns are not "NA" per row in a matrix?
body: <p>I have a matrix with 12 rows and 77 columns, but to simply lets use:  </p>
  
  <pre><code>p &lt;- matrix(NA,5,7)  
  p[1,2]&lt;-0.3  
  p[1,3]&lt;-0.5  
  p[2,4]&lt;-0.9  
  p[2,7]&lt;-0.4  
  p[4,5]&lt;-0.6 
  </code></pre>
  
  <p>I want to know which columns are not "NA" per row, so what I would like to get would be something like:  </p>
  
  <pre><code>[1] 2,3  
  [2] 4  
  [3] 0  
  [4] 5  
  [5] 0 
  </code></pre>
  
  <p>but if I do <code>&gt; which(p[]!="NA")</code> I get <code>[1]  6 11 17 24 32</code> </p>
  
  <p>I tried using a loop:  </p>
  
  <pre><code>aux &lt;- matrix(NA,5,7)  
  for(i in 1:5) {  
      aux[i,]&lt;-which(p[i,]!="NA")  
  }
  </code></pre>
  
  <p>but I just get an error: <code>number of items to replace is not a multiple of replacement length</code></p>
  
  <p>Is there a way of doing this? Thanks in advance </p>