【问题标题】:R filtering table and inserting information [duplicate]R过滤表和插入信息[重复]
【发布时间】:2017-02-01 14:23:29
【问题描述】:

我目前有以下表结构

表 1

id  a
11  4
11  3
22  1
22  3
22  5
33  2
33  1
44  6
44  8
66  5
66  7
77  6

表2

id  score 
11  12
33  22
44  20

我想删除 Table1 中不包含 Table2$id 中任何 id 的每一行。 unique(Table2$id) 应该生成这样一个唯一的 id 列表。此外,我需要将 Table2 中的 score 写入 Table1 的每个对应 id。所需的数据框是:

结果

id  a score 
11  4 12
11  3 12
33  2 22
33  1 22
44  6 20
44  8 20

【问题讨论】:

    标签: r dataframe filter merge


    【解决方案1】:
    merge(Table2, Table1, by = "id")
    

    应该这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 2013-02-26
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      相关资源
      最近更新 更多