在另一个数据框中存在数据帧中的R
我有两个dataframes a和b:
A
x y
1 0.0 0.0000000
2 0.5 0.8000000
3 -0.5 0.8000000
4 -1.0 0.0000000
5 -0.5 -0.8000000
6 0.5 -0.8000000
7 1.0 0.0000000
8 1.5 0.8000000
B
x y
1 -1.0 0.0000000
2 0.5 -0.8000000
3 3.0 0.0000000
我只想在B中存在的A中提取的行索引,以便最终结果将是:
C(4,6)
我应该如何做到这一点?
I have two dataframes A and B:
A
x y
1 0.0 0.0000000
2 0.5 0.8000000
3 -0.5 0.8000000
4 -1.0 0.0000000
5 -0.5 -0.8000000
6 0.5 -0.8000000
7 1.0 0.0000000
8 1.5 0.8000000
B
x y
1 -1.0 0.0000000
2 0.5 -0.8000000
3 3.0 0.0000000
I want to extract just the row indexes in A that exist in B so that the final result will be:
c(4,6)
How should I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
交互
可用于在多列上使用%中的%。
数据
interaction
could be used to use%in%
on multiple columns.Data
将另一列添加到A只是一个序列的A,然后合并
Add another column to A which is just a sequence and then merge
使用
join.keys
来自plyr
的函数:输出:
Using the
join.keys
function fromplyr
:Output:
一种可能的方法是计算出现True两次的次数。如果列变得更宽,则可以在它们上映射。
4 6
One possible way is to count the number of times TRUE appears twice. If the columns get wider you can map over them.
4 6
使用
外部
或循环的
Using
outer
or a
for
loop数据
Data