使用 dplyr 编程
Dr. Chester Ismay
Educator, Data Scientist, and R/Python Consultant
比较并合并两个来源的数据
dplyr 提供多种针对 tibble 的集合运算函数





uruguay_imf
# A tibble: 9 x 4
iso country year consumer_price_index
<chr> <chr> <int> <dbl>
1 URY Uruguay 2011 105.
2 URY Uruguay 2012 114.
3 URY Uruguay 2013 123.
4 URY Uruguay 2014 134.
5 URY Uruguay 2015 146.
6 URY Uruguay 2016 160.
7 URY Uruguay 2017 170.
8 URY Uruguay 2018 183.
9 URY Uruguay 2019 197.
uruguay_wb
# A tibble: 4 x 4
iso country year perc_rural_pop
<chr> <chr> <dbl> <dbl>
1 URY Uruguay 2013 5.16
2 URY Uruguay 2014 5.06
3 URY Uruguay 2015 4.96
4 URY Uruguay 2016 4.86
intersect(uruguay_imf, uruguay_wb)
Error: not compatible:
not compatible:
- Cols in y but not x: `perc_rural_pop`.
- Cols in x but not y: `consumer_price_index`.
intersect(uruguay_imf$year, uruguay_wb$year)
[1] 2013 2014 2015 2016
intersect() 查找共有的"行"inner_join() 匹配单个键值这是一个重要区别。
使用 dplyr 编程