|
|
7 vuotta sitten | |
|---|---|---|
| R | 7 vuotta sitten | |
| images | 7 vuotta sitten | |
| man | 7 vuotta sitten | |
| .Rbuildignore | 7 vuotta sitten | |
| .gitignore | 7 vuotta sitten | |
| DESCRIPTION | 7 vuotta sitten | |
| LICENSE | 7 vuotta sitten | |
| NAMESPACE | 7 vuotta sitten | |
| README.Rmd | 7 vuotta sitten | |
| README.md | 7 vuotta sitten | |
| install.R | 7 vuotta sitten | |
| runtime.txt | 7 vuotta sitten | |
| tidy-animated-verbs.Rproj | 7 vuotta sitten | |
Garrick Aden-Buie – @grrrck – garrickadenbuie.com. Set operations contributed by Tyler Grant Smith.
Mutating Joins: inner_join(), left_join(), right_join(), full_join()
Filtering Joins: semi_join(), anti_join()
Set Operations: union(), union_all(), intersect(), setdiff()
Learn more about
Please feel free to use these images for teaching or learning about action verbs from the tidyverse. You can directly download the original animations or static images in svg or png formats, or you can use the scripts to recreate the images locally.
Currently, the animations cover the dplyr two-table verbs and I’d like to expand the animations to include more verbs from the tidyverse. Suggestions are welcome!
The library can be installed with
library(tidyAnimatedVerbs)
x <- data_frame(
id = 1:3,
x = paste0("x", 1:3)
)
y <- data_frame(
id = (1:4)[-3],
y = paste0("y", (1:4)[-3])
)
animate_full_join(x, y, by = c("id"), export = "first")
x
#> # A tibble: 3 x 2
#> id x
#> <int> <chr>
#> 1 1 x1
#> 2 2 x2
#> 3 3 x3
y
#> # A tibble: 3 x 2
#> id y
#> <int> <chr>
#> 1 1 y1
#> 2 2 y2
#> 3 4 y4All rows from
xwhere there are matching values iny, and all columns fromxandy.

inner_join(x, y, by = "id")
#> # A tibble: 2 x 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
#> 2 2 x2 y2All rows from
x, and all columns fromxandy. Rows inxwith no match inywill haveNAvalues in the new columns.

left_join(x, y, by = "id")
#> # A tibble: 3 x 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
#> 2 2 x2 y2
#> 3 3 x3 <NA>… If there are multiple matches between
xandy, all combinations of the matches are returned.
y_extra <- bind_rows(y, data_frame(id = 2, y = "y5"))
y_extra # has multiple rows with the key from `x`
#> # A tibble: 4 x 2
#> id y
#> <dbl> <chr>
#> 1 1 y1
#> 2 2 y2
#> 3 4 y4
#> 4 2 y5
animate_left_join(x, y_extra, by = "id")
left_join(x, y_extra, by = "id")
#> # A tibble: 4 x 3
#> id x y
#> <dbl> <chr> <chr>
#> 1 1 x1 y1
#> 2 2 x2 y2
#> 3 2 x2 y5
#> 4 3 x3 <NA>All rows from y, and all columns from
xandy. Rows inywith no match inxwill haveNAvalues in the new columns.

right_join(x, y, by = "id")
#> # A tibble: 3 x 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
#> 2 2 x2 y2
#> 3 4 <NA> y4All rows and all columns from both
xandy. Where there are not matching values, returnsNAfor the one missing.

full_join(x, y, by = "id")
#> # A tibble: 4 x 3
#> id x y
#> <int> <chr> <chr>
#> 1 1 x1 y1
#> 2 2 x2 y2
#> 3 3 x3 <NA>
#> 4 4 <NA> y4All rows from
xwhere there are matching values iny, keeping just columns fromx.

All rows from
xwhere there are not matching values iny, keeping just columns fromx.

x <- tibble::tribble(
~x, ~y,
"1", "a",
"1", "b",
"2", "a"
)
y <- tibble::tribble(
~x, ~y,
"1", "a",
"2", "b"
)
animate_union(x, y, export = "first")
x
#> # A tibble: 3 x 2
#> x y
#> <chr> <chr>
#> 1 1 a
#> 2 1 b
#> 3 2 a
y
#> # A tibble: 2 x 2
#> x y
#> <chr> <chr>
#> 1 1 a
#> 2 2 bAll unique rows from
xandy.


All rows from
xandy, keeping duplicates.

union_all(x, y)
#> # A tibble: 5 x 2
#> x y
#> <chr> <chr>
#> 1 1 a
#> 2 1 b
#> 3 2 a
#> 4 1 a
#> 5 2 bCommon rows in both
xandy, keeping just unique rows.

All rows from
xwhich are not also rows iny, keeping just unique rows.


The Relational Data chapter of the R for Data Science book by Garrett Grolemund and Hadley Wickham is an excellent resource for learning more about relational data.
The dplyr two-table verbs vignette and Jenny Bryan’s Cheatsheet for dplyr join functions are also great resources.
The animations were made possible by the newly re-written gganimate package by Thomas Lin Pedersen (original by Dave Robinson). The package readme provides an excellent (and quick) introduction to gganimte.