title: How to create another table in R to calculate the difference?
body: <p>I have a set of data frame as below:</p>
  <blockquote>
  </blockquote>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>Parameter</th>
  <th>value</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>123-01</td>
  <td>a1</td>
  <td>x</td>
  </tr>
  <tr>
  <td>123-02</td>
  <td>a1</td>
  <td>x</td>
  </tr>
  <tr>
  <td>123-01</td>
  <td>b3</td>
  <td>x</td>
  </tr>
  <tr>
  <td>123-02</td>
  <td>b3</td>
  <td>x</td>
  </tr>
  <tr>
  <td>124-01</td>
  <td>a1</td>
  <td>x</td>
  </tr>
  <tr>
  <td>125-01</td>
  <td>a1</td>
  <td>x</td>
  </tr>
  <tr>
  <td>126-01</td>
  <td>a1</td>
  <td>x</td>
  </tr>
  <tr>
  <td>124-01</td>
  <td>b3</td>
  <td>x</td>
  </tr>
  <tr>
  <td>125-01</td>
  <td>b3</td>
  <td>x</td>
  </tr>
  <tr>
  <td>126-01</td>
  <td>b3</td>
  <td>x</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I would like to find the sampleID that ended with &quot;-02&quot;, and calculate the difference of the same sample ID that has the same first three digit by same parameter.</p>
  <p>For example, calculate the difference of 123-01 and 123-02 based on parameter a1. Then the difference of 123-01 and 123-02 based on parameter b3, etc....</p>
  <p>In the end, I can get a table contains</p>
  <blockquote>
  </blockquote>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">ID</th>
  <th style="text-align: center;">Parameter</th>
  <th style="text-align: right;">DiffValue</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">123</td>
  <td style="text-align: center;">a1</td>
  <td style="text-align: right;">y</td>
  </tr>
  <tr>
  <td style="text-align: left;">123</td>
  <td style="text-align: center;">b3</td>
  <td style="text-align: right;">y</td>
  </tr>
  <tr>
  <td style="text-align: left;">127</td>
  <td style="text-align: center;">a1</td>
  <td style="text-align: right;">y</td>
  </tr>
  <tr>
  <td style="text-align: left;">127</td>
  <td style="text-align: center;">b3</td>
  <td style="text-align: right;">y</td>
  </tr>
  </tbody>
  </table>
  </div>
  <blockquote>
  </blockquote>
  <p>How can I do it?</p>
  <p>I tried to use dplyr (filter) to create a table that only contains the duplicate, and then how do I match the origin table and do the calculation?</p>