title: Need R function to manipulate two data frames
body: <p>Can I get some help writing an efficient R function for this situation?
  I have a Summary and a detail table.  I would like to replace the values in the Summary table (or create another Output Table) with matching values in the Detail table based on some conditions.  I need help with R script that can accomplish the following: </p>
  
  <p>a)  For each unique combination of (Name and Date) in the summary Table A</p>
  
  <p>a.  Perform the following for matching records on Table B (Detail Table): </p>
  
  <p>i.  If  sum of Value A = Sum of Value B then Copy/replace records with Detail</p>
  
  <p>ii. If the sum of Value A is not equal to Sum of Value (B) </p>
  
  <ol>
  <li>Find the difference </li>
  <li>Add that difference to the Type “P” value in Table B to ensure that the sums match. .</li>
  <li>Then copy to new table or replace the records (with the adjusted “P” value)  with the details. </li>
  </ol>
  
  <p>Table A: </p>
  
  <pre><code>Name    Date    valueA
  A   1/2/2016    21
  A   1/3/2016    27
  B   1/2/2016    50
  </code></pre>
  
  <p>Table B: </p>
  
  <pre><code>Name    Date    Type    ValueB
  A   1/2/2016    F   10
  A   1/2/2016    P   11
  A   1/3/2016    F   12
  A   1/3/2016    F   13
  A   1/3/2016    P   2
  B   1/2/2016    F   25
  B   1/2/2016    P   12
  </code></pre>
  
  <p>Expected Output                         </p>
  
  <pre><code>Name    Date    Type    Value                   
  A   1/2/2016    F   10                  
  A   1/2/2016    P   11                  
  A   1/3/2016    F   12                  
  A   1/3/2016    F   13                  
  A   1/3/2016    P   2                   
  B   1/2/2016    F   25                  
  B   1/2/2016    P   25  &lt;&lt;-- Adjust Values of "P" type with the difference
  </code></pre>