【发布时间】:2021-01-25 11:33:47
【问题描述】:
我有一个大型临床数据数据框(154 个变量的 882 个 obs)。在这个数据框中,有 441 名独特的患者,重复两次,除了一列。所以表格的虚拟版本如下所示:
| id | age | gender | tumour | type | treatment |
|---|---|---|---|---|---|
| 1 | 76 | F | colon | adeno | radiotherapy |
| 1 | 76 | F | colon | adeno | chemotherapy |
| 2 | 70 | M | colon | adeno | radiotherapy |
| 2 | 70 | M | colon | adeno | chemotherapy |
| 3 | 68 | M | colon | adeno | radiotherapy |
| 3 | 68 | M | colon | adeno | chemotherapy |
我想把这张表压缩成这样:
| id | age | gender | tumour | type | treatment_a | treatment_b |
|---|---|---|---|---|---|---|
| 1 | 76 | F | colon | adeno | radiotherapy | chemotherapy |
| 2 | 70 | M | colon | adeno | radiotherapy | chemotherapy |
| 3 | 68 | M | colon | adeno | radiotherapy | chemotherapy |
我在网上查看并尝试使用类似问题的解决方案,例如。 sapply、group_by、summarise 和 distinct 但我似乎无法正确使用语法。
我完全是新手,这似乎是一个简单的问题。提前致谢。
【问题讨论】:
标签: r dataframe data-manipulation