title: Why does scale return NaN for zero variance columns?
body: <p>Consider the following matrix:</p>
  
  <pre><code>x &lt;- matrix(c(1,1,1,3),2)
  x
       [,1] [,2]
  [1,]    1    1
  [2,]    1    3
  </code></pre>
  
  <p>When calling <code>scale</code> with this, <code>NaN</code> values are returned for the first column, which has zero variance:</p>
  
  <pre><code>scale(x)
       [,1]       [,2]
  [1,]  NaN -0.7071068
  [2,]  NaN  0.7071068
  attr(,"scaled:center")
  [1] 1 2
  attr(,"scaled:scale")
  [1] 0.000000 1.414214
  </code></pre>
  
  <p>However, I would expect it to return <code>0</code>. Is this a bug or am I misunderstanding what this is and should return?</p>
  
  <p>The work around for what I want is:</p>
  
  <pre><code>y &lt;- scale(x)
  y[is.nan(y)] &lt;- 0
  </code></pre>
  
  <p>But this involves the use of an extra variable, is there a more elegant solution?</p>