r - Is there a R function to compare the frequency of occurrences of row elements between two dataframes?
问题描述
Say I have two dataframes
df1
Var1=c("a", "b", "c")
Freq= c(1, 3, 8)
df2
Var1= c("a", "b", "c")
Freq= c(5, 3, 8)
so I want my output to be y & z as their frequencies match between the two dataframes.
解决方案
使用 dplyr:
> df1
Var1 Freq
1 x 1
2 y 3
3 z 8
> df2
Var1 Freq
1 x 5
2 y 3
3 z 8
> df1 %>% inner_join(df2, by = c('Var1' = 'Var1', 'Freq' = 'Freq' )) %>% pull(1)
[1] "y" "z"
推荐阅读
- intellij-idea - SVN 在两个不同的更改列表中处理一个文件
- javascript - Buddypress jq.cookie 不是函数
- asp.net - 创建新项目时如何更改 dotnet new 模板的名称?
- c++ - 在另一个类 C++ 中使用对象的重载 istream
- java - getTables 方法不接受架构参数并从所有架构返回表
- python - 我没有手动确认消息,然后rabbitmq在1分钟后再次给它,我可以延长这个时间吗?
- android - 如何将自定义 XML 布局膨胀到自定义 ItemDecoration?
- r - 带有 ggplot2 geom_bar 的分组条形图正在绘制比例而不是计数
- sql - 如何从mssql中的一个到多个相关表中获取每个id的单个记录
- php - 必须禁用先前用户选中的所有复选框