用R中的匹配ID替换单元格
i dataFrame(XLSX文件)的形式:(此DataFrame具有152069行)。
源 | 目标 |
---|---|
dortmund | antwerp |
孟买 | Spijkenisse |
xioalan | beilun beilun |
ettringen | bremerhaven |
hilter | bremerhaven |
和我还有另一个带有IDS和名称的数据框:(此DataFrame具有10200行,每个名称唯一的ID)。
ID | 名称 |
---|---|
2678 | Dortmund |
6049 | 孟买 |
9873 | Xioalan |
3014 | Ettringen |
4055 | Hilter |
338 | Antwerp |
8323 | Spijkenisse |
824 | Beilun |
1272 | Bremerhaven, |
我想用适当的ID替换第一个数据框架的数据(在第二个数据Frame中)。您对如何执行此操作有任何建议吗?先感谢您。
I a dataframe (xlsx file) in the form: (this dataframe has 152069 rows).
Source | Target |
---|---|
DORTMUND | ANTWERP |
MUMBAI | SPIJKENISSE |
XIOALAN | BEILUN |
ETTRINGEN | BREMERHAVEN |
HILTER | BREMERHAVEN |
and I also have another dataframe with the Ids and Names: (this dataframe has 10200 rows with unique id's for each name).
ID | Name |
---|---|
2678 | DORTMUND |
6049 | MUMBAI |
9873 | XIOALAN |
3014 | ETTRINGEN |
4055 | HILTER |
338 | ANTWERP |
8323 | SPIJKENISSE |
824 | BEILUN |
1272 | BREMERHAVEN |
I would like to replace the data of the first dataframe with their appropriate id (in the second dataframe). Do you have any suggestions on how to do this? Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
匹配第一个DFRM数据的
第二次DFRMname
创建索引,以应用于第二个数据框架的ID列。显然,这应该在您具有足够备份的R对象上完成。Use
match
of first dfrm data agains second dfrmName
to create an index to apply to the ID column of the second dataframe. Obviously this should be done on R object for which you have adequate backups.使用基本R,您可以使用
匹配
将名称配对在一起,然后我们可以获得id
供每列替换的:output
又选项将再次突变并使用
匹配
:另一个选项是旋转到长形式,然后将数据连接在一起,然后重新启动宽(但不是很高效)。
数据
With base R, you can use
match
to pair the names together then we can get theID
for those to replace for each column:Output
Another option would be to mutate across and use
match
again:Another option would be to pivot to long form, then join the data together then pivot back wide (but not very efficient).
Data