根据单个公共值来压缩行

时间:2018-03-23 07:48:09

标签: r

我有数据,每行都有一个ID。对于某些行,ID与其他行匹配。这意味着他们是同一组"的一部分。他们可能在不同的列中有价值,但他们不会超过一圈。我试图用相同的ID压缩行,但无法弄明白,(因此在下面的示例中,结果只有3行,对于ID 1 2和3)

示例(运行代码段):

我已尝试使用aggregate,但我找不到字符串的连接函数。感谢。



<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-yw4l{vertical-align:top}
</style>
<table class="tg">
  <tr>
    <th class="tg-yw4l">ID</th>
    <th class="tg-yw4l">Name</th>
    <th class="tg-yw4l">Info</th>
    <th class="tg-yw4l">A</th>
    <th class="tg-yw4l">B</th>
  </tr>
  <tr>
    <td class="tg-yw4l">1</td>
    <td class="tg-yw4l">Jack</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
  </tr>
  <tr>
    <td class="tg-yw4l">1</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">ABC</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">x</td>
  </tr>
  <tr>
    <td class="tg-yw4l">1</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">x</td>
    <td class="tg-yw4l"></td>
  </tr>
  <tr>
    <td class="tg-yw4l">2</td>
    <td class="tg-yw4l">Marin</td>
    <td class="tg-yw4l">ABC</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
  </tr>
  <tr>
    <td class="tg-yw4l">2</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">Y</td>
    <td class="tg-yw4l"></td>
  </tr>
  <tr>
    <td class="tg-yw4l">3</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">X</td>
  </tr>
  <tr>
    <td class="tg-yw4l">3</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">ABC</td>
    <td class="tg-yw4l">X</td>
    <td class="tg-yw4l"></td>
  </tr>
  <tr>
    <td class="tg-yw4l">3</td>
    <td class="tg-yw4l">Giraffe</td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l"></td>
    <td class="tg-yw4l">Y</td>
  </tr>
</table>
&#13;
&#13;
&#13;

0 个答案:

没有答案