我有两个结构不同的 Dataframe df_1
和df_2
,但我想使用left_join将列从一个df添加到另一个df。
我的主df df_1
看起来像这样:
structure(list(ID = c("131", "131", "206", "206", "5", "2"),
Company = c("ABC", "ABC", "DEF", "DEF", "EFD", "SDF"), Name = c("Alex",
"Marian", "Peter", "Maria", "Mila", "Maya"), Degree = c("0",
"1", "1", "0", "1", "0")), class = "data.frame", row.names = c(NA,
-6L))
ID Company Name Degree
131 ABC Alex 0
131 ABC Marian 1
206 DEF Peter 1
206 DEF Maria 0
5 EFD Mila 1
2 SDF Maya 0
我的第二个df df_2
看起来像这样:
structure(list(ID = c("131", "206", "5", "2"), Company = c("ABC",
"DEF", "EFD", "SDF"), Name_1 = c("Alex", "Peter", "Mila", "Maya"
), Name_2 = c("Marian", "Maria", NA, NA), Achiev = c("1234",
"2341", "43", "22")), class = "data.frame", row.names = c(NA,
-4L))
ID Company Name_1 Name_2 Achiev
131 ABC Alex Marian 1234
206 DEF Peter Maria 2341
5 EFD Mila NA 43
2 SDF Maya NA 22
我想基于列ID
、Company
和Name
将列Achiev
连接到df_1
。
在我的原始版本中,我在每个dataframe中有超过500个列,我想至少对几个列执行这种转换,请记住这一点。
2条答案
按热度按时间vaqhlq811#
创建于2023-04-25使用reprex v2.0.2
7vux5j2d2#
我猜 Name_1 和 Name_2 必须以某种方式处理,例如通过组合
df2
的 Names