You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R语言中找出两个DataFrame的共同区域并生成新DataFrame

简洁提取两个DataFrame共有的区域列

要生成仅包含firstdf和seconddf共有的区域的单列DataFrame,用基础R的intersect()函数就能直接实现,无需复杂操作:

# 提取两个区域列的交集,转为单列DataFrame
thirddf <- data.frame(area = intersect(firstdf$area1, seconddf$area2))

# 查看结果
thirddf

运行后得到的thirddf就是预期结果:

area
1  005
2  007
3  011
4  013
5  015
6  021

内容的提问来源于stack exchange,提问作者Tim Wilcox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 03:01:13