title: How to calculate the median for a part of a column based on unique names from another column (Rstudio)?
body: <p>I have a data frame with 4 columns (not counting rownames) and &gt;1200 rows.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>(unique cell ID; rownames)</th>
  <th>Sample ID</th>
  <th>ME.brown</th>
  <th>ME.turquoise</th>
  <th>ME.blue</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>p1t1_bcHTNA</td>
  <td>p1t1</td>
  <td>-0.004</td>
  <td>0.0023</td>
  <td>0.00683</td>
  </tr>
  <tr>
  <td>p1t1_bcHNVA</td>
  <td>p1t1</td>
  <td>0.0054</td>
  <td>-0.0123</td>
  <td>0.0045</td>
  </tr>
  <tr>
  <td>p1t2_bcEZOJ</td>
  <td>p1t2</td>
  <td>-0.0022</td>
  <td>0.00354</td>
  <td>0.00374</td>
  </tr>
  <tr>
  <td>K3-B003528</td>
  <td>LT_S58</td>
  <td>0.0464</td>
  <td>0.00734</td>
  <td>-0.0013</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I have &gt; 1200 unique cell IDs, which correspond to 68 samples (Sample ID) in total. Now, what I want to do is to calculate the median value for each ME (brown, turquoise and blue) PER SAMPLE. So ideally I want to end up with a table containg 68 rows (for every unique sample) and 3 columns for every ME median. I don't know how to do it apart from manually subsetting each of the 68 unique samples, which would not be very efficient.</p>
  <p>I would appreciate all help.</p>
  <p>BW</p>