title: Merging dataframes with all.equal on numeric(float) keys?
body: <p>I have two data frames I want to merge based on a numeric value, however I am having trouble with floating point accuracy. Example:</p>
  
  <pre><code>&gt; df1 &lt;- data.frame(number = 0.1 + seq(0.01,0.1,0.01), letters = letters[1:10])
  &gt; df2 &lt;- data.frame(number = seq(0.11,0.2,0.01), LETTERS = LETTERS[1:10])
  &gt; (merged &lt;- merge(df1, df2, by = "number", all = TRUE))
     number letters LETTERS
  1    0.11       a       A
  2    0.12    &lt;NA&gt;       B
  3    0.12       b    &lt;NA&gt;
  4    0.13       c       C
  5    0.14       d       D
  6    0.15    &lt;NA&gt;       E
  7    0.15       e    &lt;NA&gt;
  8    0.16       f       F
  9    0.17       g       G
  10   0.18       h       H
  11   0.19       i       I
  12   0.20       j       J
  </code></pre>
  
  <p>Some of the values (0.12 and 0.15) don't match up due to floating point accuracy issues as <a href="https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal">discussed in this post</a>.  The solution for finding equality there was the use of the <code>all.equal</code> function to remove floating point artifacts, however I don't believe there is a way to do this within the <code>merge</code> function.</p>
  
  <p>Currently I get around it by forcing one of the the <code>number</code> columns to a character and then back to a number after <code>merge</code>, but this is a little clunky; does anyone have a better solution for this problem?</p>
  
  <pre><code>&gt; df1c &lt;- df1
  &gt; df1c[["number"]] &lt;- as.character(df1c[["number"]])
  &gt; merged2 &lt;- merge(df1c, df2, by = "number", all = TRUE)
  &gt; merged2[["number"]] &lt;- as.numeric(merged2[["number"]])
  &gt; merged2
     number letters LETTERS
  1    0.11       a       A
  2    0.12       b       B
  3    0.13       c       C
  4    0.14       d       D
  5    0.15       e       E
  6    0.16       f       F
  7    0.17       g       G
  8    0.18       h       H
  9    0.19       i       I
  10   0.20       j       J
  </code></pre>
  
  <p>EDIT: A little more about the data</p>
  
  <ul>
  <li>I wanted to keep my question general to make it more applicable to other people's problems, but it seems I may need to be more specific to get an answer.</li>
  <li>It is likely that all of the issues with merging with be due to floating point inaccuracy, but it may be a little hard to be sure.  The data comes in as a series of time series values, a start time, and a frequency.  These are then turned into a time series (<code>ts</code>) object and a number of functions are called to extract features from the time series (one of which is the <code>time</code> value), which is returned as a data frame.  Meanwhile another set of functions is being called to get other features from the time series as targets.  There are also potentially other series getting features generated to complement the original series.  These values then have to be reunited using the <code>time</code> value.</li>
  <li><strong>Can't store as <code>POSIXct</code>:</strong> Each of these processes (feature extraction, target computation, merging) has to be able to occur independently and be stored in a CSV type format so it can be passed to other platforms.  Storing as a <code>POSIXct</code> value would be difficult since the series aren't necessarily stored in calendar times.</li>
  </ul>