Linhas que se cruzam não são paralelas

Programando com dplyr

Dr. Chester Ismay

Educator, Data Scientist, and R/Python Consultant

Operações de teoria de conjuntos

  • Compare e combine dados de duas fontes

  • dplyr tem funções para aplicar operações de teoria de conjuntos em tibbles

Programando com dplyr

Diagramas de Venn para teoria de conjuntos

Diagrama de interseção

Diagrama de união

Diagrama de união total

Diagrama de diferença de conjuntos

Programando com dplyr

diagrama de intersect

diagrama de intersect

Programando com dplyr

Tibbles do Uruguai

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
Programando com dplyr

Testando intersect()

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
Programando com dplyr

Diferença entre intersect() e um join

  • intersect() busca linhas em comum
  • inner_join() busca chaves que coincidem

Essa diferença é importante.

Programando com dplyr

Vamos praticar!

Programando com dplyr

Preparing Video For Download...