title: subsetting matrix including NA's
body: <p>I have a matrix like so:</p>
  
  <pre><code>     a    b    c    d
  [1]  as   ac   ad   ae
  [2]  bd   bf   bg   bh
  [3]  NA   cf   cd   ce
  [4]  NA   NA   dr   dy
  [5]  NA   NA   NA   ej 
  </code></pre>
  
  <p>I would like to subset every column separately into a matrix or list based on 50% of the observations, so I would like my output to look like this:</p>
  
  <pre><code>     a    b    c    d
  [1]  as   ac   ad   ae
  [2]  NA   bf   bg   bh
  [3]  NA   NA   NA   ce
  </code></pre>
  
  <p>So far I have used to code for separate columns without NA's.</p>
  
  <pre><code>mv.s &lt;- subset(mv, mv &lt;= quantile(mv, 0.5))    
  </code></pre>
  
  <p>now I was thinking of using something like </p>
  
  <pre><code>for (i in 1:15) {
  mv.s[[i]] &lt;- subset(mv[[i]], mv &lt;= quantile(mv, 0.5))
  }
  </code></pre>
  
  <p>However, when I do this I get the warning:</p>
  
  <blockquote>
    <p>Error in quantile.default(mv, 0.5) : 
        missing values and NaN's not allowed if 'na.rm' is FALSE</p>
  </blockquote>
  
  <p>when I try this code:</p>
  
  <pre><code>for (i in 1:15) {
  mv.s[[i]] &lt;- subset(mv[[i]], mv &lt;= quantile(mv[[i]], 0.5))
  }
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>Error in (1 - h) * qs[i] : non-numeric argument to binary operator </p>
  </blockquote>
  
  <p>Any help would be appreciated.</p>