title: How to use dplyr::nest to work out the difference between two data sets
body: <p>1) I have a transactional file called - "UBER" <br/>
  2) I also have a "Target" df to which totals I need to match my "UBER" totals  <br/>
  3) I need to find the difference between Target and UBER (~ Target - UBER)  <br/>
  4) and then I will overlay the difference to UBER which will then make UBER = Target</p>
  
  <h1>Data for UBER - transactional file</h1>
  
  <pre><code>UBER &lt;- data.frame(
      Cube = c("UBER", "UBER", "UBER", "UBER"),
   Country = c("AU", "AU", "AU", "AU"),
   Product = c("0001", "0001", "0001", "0001"),
       LOB = c("xxx", "xxx", "xxx", "xxx"),
    Mth_Yr = 1:4,
   Revenue = c(5, 5, 5, 5)
      )
  </code></pre>
  
  <h1>The Target df should be</h1>
  
  <pre><code>Target &lt;- data.frame(
      Cube = c("Target", "Target", "Target", "Target"),
   Country = c("AU", "AU", "AU", "AU"),
   Product = c("0001", "0001", "0001", "0001"),
       LOB = c("xxx", "xxx", "xxx", "xxx"),
    Mth_Yr = 1:4,
   Revenue = c(10, 10, 10, 10)
        )
  </code></pre>
  
  <h1>I have built a function to help me with the analysis:</h1>
  
  <pre><code>target_less_uber &lt;- function(df){
  
    target &lt;- df %&gt;% #as.data.frame() %&gt;%
          filter(Cube == "Target") %&gt;%
          select(Revenue) %&gt;% as.numeric()
  
    uber  &lt;- df %&gt;% #as.data.frame() %&gt;%
          filter(Cube == "UBER") %&gt;%
          select(Revenue) %&gt;% as.numeric()      
  
    output &lt;- data.frame(Overlay = target - uber)
  
    return(output)
  </code></pre>
  
  <p>}</p>
  
  <h1>This is what I tried - which is not working</h1>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>library(dplyr)
  library(purrr)
  
  ALL &lt;- rbind(Target, UBER)
  ALL %&gt;%
        nest(Cube, Revenue) %&gt;%
        transmute(Country, Product, LOB, Mth_Yr, res = map(data, target_less_uber) %&gt;% unnest </code></pre>
  </div>
  </div>
  </p>
  
  <p>Any help advice is highly appreciated. </p>