title: R: integer versus numeric
body: <p>This question perhaps has been answered earlier, but I did not see an answer.</p>
  
  <p>I have a data set that consists of numbers and missing values.  One row is a percentage.  Below is a small set of fake data where AA, BB and CC are the column names.  The third row in this data set is the percentage.</p>
  
  <pre><code>   AA    BB    CC
    234   432    78
   1980  3452  2323
   91.1    90  93.3
     34   123    45
  </code></pre>
  
  <p>In this case, when I read the data set AA and CC are numeric and BB is integer.  I guess somewhere 90.0 was rounded to 90.  If I do not specify that BB is numeric could this cause problems with basic arithmetic?</p>
  
  <p>I believe that if dd = 1 and ee = 2 and both are integer then the C language says dd / ee = 0, while R says dd / ee = 0.5.</p>
  
  <p>Below is a series of simple mathematical operations that all seem to suggest answers in R are not changed regardless of whether the data are numeric or integer.  Nevertheless, I keep thinking that it would be smart to specify that all variables are numeric when reading the data.  Using Google I have found an example or two where the data type did seem to make a difference, but not below.</p>
  
  <pre><code>aa &lt;- c(1,2,3,4,5,6,7)
  bb &lt;- 2
  str(aa)
  str(bb)
  
  cc &lt;- as.integer(aa)
  dd &lt;- as.integer(bb)
  str(cc)
  str(dd)
  
  aa/bb
  cc/dd
  aa/dd
  cc/bb
  
  ee &lt;- aa * aa
  str(ee)
  sum(ee/2)
  
  ff &lt;- cc * cc
  str(ff)
  sum(ff/2)
  
  gg &lt;- 4.14
  
  hh &lt;- ((aa * aa) * gg) / 2
  hh
  ii &lt;- ((cc * cc) * gg) / 2
  ii
  
  jj &lt;- (aa * aa) / gg
  jj
  kk &lt;- (cc * cc) / gg
  kk
  jj == kk
  
  mm &lt;- as.integer(1)
  nn &lt;- as.integer(2)
  mm/nn
  </code></pre>
  
  <p>I guess I am hoping for reassurance that this is not likely an issue with simple math, but I suspect it can.  I keep thinking there is a fundamental rule of programming here, but I am not sure what that is.  (I am aware of the concept of double precision.)</p>
  
  <p>Thanks for any advice with what is surely a basic issue.</p>