title: `round()` to many digits in R
body: <p>I am using the <code>round()</code> function that, according to the help</p>
  
  <blockquote>
    <p>rounds the values in its first argument to the specified number
    of decimal places (default 0).</p>
  </blockquote>
  
  <p>And the <code>digits</code> argument in <code>round(x, digits = 0)</code> is an</p>
  
  <blockquote>
    <p>integer indicating the number of decimal places (round) .</p>
  </blockquote>
  
  <p>Could someone explain this output? Because it does not seem to work as advertised. But perhaps I just overlooked something.</p>
  
  <pre><code>&gt; round(x = 234234.3456789, digits = 0)
  [1] 234234
  &gt; round(x = 234234.3456789, digits = 1)
  [1] 234234.3
  &gt; round(x = 234234.3456789, digits = 2)
  [1] 234234.4
  &gt; round(x = 234234.3456789, digits = 3)
  [1] 234234.3
  &gt; round(x = 234234.3456789, digits = 4)
  [1] 234234.3
  &gt; round(x = 234234.3456789, digits = 5)
  [1] 234234.3
  &gt; round(x = 234234.3456789, digits = 6)
  [1] 234234.3
  &gt; round(x = 234234.3456789, digits = 7)
  [1] 234234.3
  </code></pre>
  
  <p>I tried changing the number and it seems it is not rounding to the number of decimal places indicated by digits (as indicated), but rather to the total number of places indicated by the argument digits</p>
  
  <pre><code>&gt;     round(x = 34.3456789, digits = 0)
  [1] 34
  &gt;     round(x = 34.3456789, digits = 1)
  [1] 34.3
  &gt;     round(x = 34.3456789, digits = 2)
  [1] 34.35
  &gt;     round(x = 34.3456789, digits = 3)
  [1] 34.346
  &gt;     round(x = 34.3456789, digits = 4)
  [1] 34.3457
  &gt;     round(x = 34.3456789, digits = 5)
  [1] 34.34568
  &gt;     round(x = 34.3456789, digits = 6)
  [1] 34.34568
  &gt;     round(x = 34.3456789, digits = 7)
  [1] 34.34568
  </code></pre>
  
  <p>That's weird to me. But again, maybe I am just doing something wrong.</p>
  
  <p>Trying to find an explanation I found <a href="https://stackoverflow.com/questions/7681756/rounding-numbers-in-r-to-specified-number-of-digits">this other question here in SO</a> and one of the examples there actually seems to work as I expected.</p>
  
  <pre><code>x &lt;- c(pi, pi*1000, pi/1000)
  
  &gt; round(x, digits = 0)
  [1]    3 3142    0
  &gt; round(x, digits = 1)
  [1]    3.1 3141.6    0.0
  &gt; round(x, digits = 2)
  [1]    3.14 3141.59    0.00
  &gt; round(x, digits = 3)
  [1]    3.142 3141.593    0.003
  &gt; round(x, digits = 3)
  [1]    3.142 3141.593    0.003
  &gt; round(x, digits = 4)
  [1]    3.1416 3141.5927    0.0031
  &gt; round(x, digits = 5)
  [1]    3.14159 3141.59265    0.00314
  &gt; round(x, digits = 6)
  [1]    3.141593 3141.592654    0.003142
  &gt; round(x, digits = 7)
  [1]    3.1415927 3141.5926536    0.0031416
  </code></pre>
  
  <p>But when I try doing something similar with my original example, it does not work. Actually, something as similar as <code>x &lt;- c(pi, pi, pi)</code>, instead of <code>x &lt;- c(pi, pi*1000, pi/1000)</code> does not work (note the last two, it does not add another decimal place, rather it sort of cuts on 7 positions overall).</p>
  
  <pre><code>x &lt;- c(pi, pi, pi)
  &gt; round(x, digits = 0)
  [1] 3 3 3
  &gt; round(x, digits = 1)
  [1] 3.1 3.1 3.1
  &gt; round(x, digits = 2)
  [1] 3.14 3.14 3.14
  &gt; round(x, digits = 3)
  [1] 3.142 3.142 3.142
  &gt; round(x, digits = 3)
  [1] 3.142 3.142 3.142
  &gt; round(x, digits = 4)
  [1] 3.1416 3.1416 3.1416
  &gt; round(x, digits = 5)
  [1] 3.14159 3.14159 3.14159
  &gt; round(x, digits = 6)
  [1] 3.141593 3.141593 3.141593
  &gt; round(x, digits = 7)
  [1] 3.141593 3.141593 3.141593
  </code></pre>
  
  <p>I checks object class and structure, and seems the same.</p>
  
  <p>What is going on here?</p>