ソースを参照

Only attach tidyexplain in README

Calls to tidyr and dplyr are now prefixed with package name. This lets us use the README as a test to make sure all namespace issues are fixed. We can roll this back when the package is more stable.
pull/18/merge
コミット
326b48a5dc
2個のファイルの変更44行の追加49行の削除
  1. +22
    -25
      README.Rmd
  2. +22
    -24
      README.md

+ 22
- 25
README.Rmd ファイルの表示

fig.path = "man/figures/tidyexplain-", fig.path = "man/figures/tidyexplain-",
cache = TRUE cache = TRUE
) )
library(dplyr)
library(tidyexplain) library(tidyexplain)
set_font_size(11, 26) set_font_size(11, 26)
``` ```
## Mutating Joins ## Mutating Joins


```{r intial-dfs} ```{r intial-dfs}
x <- data_frame(
x <- dplyr::data_frame(
id = 1:3, id = 1:3,
x = paste0("x", 1:3) x = paste0("x", 1:3)
) )


y <- data_frame(
y <- dplyr::data_frame(
id = (1:4)[-3], id = (1:4)[-3],
y = paste0("y", (1:4)[-3]) y = paste0("y", (1:4)[-3])
) )




```{r} ```{r}
inner_join(x, y, by = "id")
dplyr::inner_join(x, y, by = "id")
``` ```


### Left Join ### Left Join




```{r} ```{r}
left_join(x, y, by = "id")
dplyr::left_join(x, y, by = "id")
``` ```


### Left Join (Extra Rows in y) ### Left Join (Extra Rows in y)
> ... If there are multiple matches between `x` and `y`, all combinations of the matches are returned. > ... If there are multiple matches between `x` and `y`, all combinations of the matches are returned.


```{r left-join-extra} ```{r left-join-extra}
y_extra <- bind_rows(y, data_frame(id = 2, y = "y5"))
y_extra <- dplyr::bind_rows(y, dplyr::data_frame(id = 2, y = "y5"))
y_extra # has multiple rows with the key from `x` y_extra # has multiple rows with the key from `x`


animate_left_join(x, y_extra, by = "id") animate_left_join(x, y_extra, by = "id")
``` ```


```{r} ```{r}
left_join(x, y_extra, by = "id")
dplyr::left_join(x, y_extra, by = "id")
``` ```


### Right Join ### Right Join




```{r} ```{r}
right_join(x, y, by = "id")
dplyr::right_join(x, y, by = "id")
``` ```


### Full Join ### Full Join




```{r} ```{r}
full_join(x, y, by = "id")
dplyr::full_join(x, y, by = "id")
``` ```


## Filtering Joins ## Filtering Joins




```{r} ```{r}
semi_join(x, y, by = "id")
dplyr::semi_join(x, y, by = "id")
``` ```


### Anti Join ### Anti Join




```{r} ```{r}
anti_join(x, y, by = "id")
dplyr::anti_join(x, y, by = "id")
``` ```


## Set Operations ## Set Operations


```{r intial-dfs-so} ```{r intial-dfs-so}
x <- data_frame(
x <- dplyr::data_frame(
x = c(1, 1, 2), x = c(1, 1, 2),
y = c("a", "b", "a") y = c("a", "b", "a")
) )
y <- data_frame(
y <- dplyr::data_frame(
x = c(1, 2), x = c(1, 2),
y = c("a", "b") y = c("a", "b")
) )




```{r} ```{r}
union(x, y)
dplyr::union(x, y)
``` ```




```{r union-y-x} ```{r union-y-x}
animate_union(y, x) animate_union(y, x)


union(y, x)
dplyr::union(y, x)
``` ```


### Union All ### Union All




```{r} ```{r}
union_all(x, y)
dplyr::union_all(x, y)
``` ```








```{r} ```{r}
intersect(x, y)
dplyr::intersect(x, y)
``` ```


### Set Difference ### Set Difference




```{r} ```{r}
setdiff(x, y)
dplyr::setdiff(x, y)
``` ```




```{r setdiff-y-x} ```{r setdiff-y-x}
animate_setdiff(y, x) animate_setdiff(y, x)


setdiff(y, x)
dplyr::setdiff(y, x)
``` ```


## Tidy Data and `gather()`, `spread()` functionality ## Tidy Data and `gather()`, `spread()` functionality
you organize your data into tidy data. you organize your data into tidy data.


```{r} ```{r}
library(tidyr)

long <- data_frame(
long <- dplyr::data_frame(
year = c(2010, 2011, 2010, 2011, 2010, 2011), year = c(2010, 2011, 2010, 2011, 2010, 2011),
person = c("Alice", "Alice", "Bob", "Bob", "Charlie", "Charlie"), person = c("Alice", "Alice", "Bob", "Bob", "Charlie", "Charlie"),
sales = c(105, 110, 100, 97, 90, 95) sales = c(105, 110, 100, 97, 90, 95)
) )
wide <- data_frame(
wide <- dplyr::data_frame(
year = 2010:2011, year = 2010:2011,
Alice = c(105, 110), Alice = c(105, 110),
Bob = c(100, 97), Bob = c(100, 97),
``` ```


```{r} ```{r}
gather(wide, key = "person", value = "sales", -year)
tidyr::gather(wide, key = "person", value = "sales", -year)
``` ```


### Spread ### Spread
``` ```


```{r} ```{r}
spread(long, key = "person", value = "sales")
tidyr::spread(long, key = "person", value = "sales")
``` ```





+ 22
- 24
README.md ファイルの表示

## Mutating Joins ## Mutating Joins


``` r ``` r
x <- data_frame(
x <- dplyr::data_frame(
id = 1:3, id = 1:3,
x = paste0("x", 1:3) x = paste0("x", 1:3)
) )


y <- data_frame(
y <- dplyr::data_frame(
id = (1:4)[-3], id = (1:4)[-3],
y = paste0("y", (1:4)[-3]) y = paste0("y", (1:4)[-3])
) )
![](man/figures/tidyexplain-inner-join-1.gif)<!-- --> ![](man/figures/tidyexplain-inner-join-1.gif)<!-- -->


``` r ``` r
inner_join(x, y, by = "id")
dplyr::inner_join(x, y, by = "id")
#> # A tibble: 2 x 3 #> # A tibble: 2 x 3
#> id x y #> id x y
#> <int> <chr> <chr> #> <int> <chr> <chr>
![](man/figures/tidyexplain-left-join-1.gif)<!-- --> ![](man/figures/tidyexplain-left-join-1.gif)<!-- -->


``` r ``` r
left_join(x, y, by = "id")
dplyr::left_join(x, y, by = "id")
#> # A tibble: 3 x 3 #> # A tibble: 3 x 3
#> id x y #> id x y
#> <int> <chr> <chr> #> <int> <chr> <chr>
> of the matches are returned. > of the matches are returned.


``` r ``` r
y_extra <- bind_rows(y, data_frame(id = 2, y = "y5"))
y_extra <- dplyr::bind_rows(y, dplyr::data_frame(id = 2, y = "y5"))
y_extra # has multiple rows with the key from `x` y_extra # has multiple rows with the key from `x`
#> # A tibble: 4 x 2 #> # A tibble: 4 x 2
#> id y #> id y
![](man/figures/tidyexplain-left-join-extra-1.gif)<!-- --> ![](man/figures/tidyexplain-left-join-extra-1.gif)<!-- -->


``` r ``` r
left_join(x, y_extra, by = "id")
dplyr::left_join(x, y_extra, by = "id")
#> # A tibble: 4 x 3 #> # A tibble: 4 x 3
#> id x y #> id x y
#> <dbl> <chr> <chr> #> <dbl> <chr> <chr>
![](man/figures/tidyexplain-right-join-1.gif)<!-- --> ![](man/figures/tidyexplain-right-join-1.gif)<!-- -->


``` r ``` r
right_join(x, y, by = "id")
dplyr::right_join(x, y, by = "id")
#> # A tibble: 3 x 3 #> # A tibble: 3 x 3
#> id x y #> id x y
#> <int> <chr> <chr> #> <int> <chr> <chr>
![](man/figures/tidyexplain-full-join-1.gif)<!-- --> ![](man/figures/tidyexplain-full-join-1.gif)<!-- -->


``` r ``` r
full_join(x, y, by = "id")
dplyr::full_join(x, y, by = "id")
#> # A tibble: 4 x 3 #> # A tibble: 4 x 3
#> id x y #> id x y
#> <int> <chr> <chr> #> <int> <chr> <chr>
![](man/figures/tidyexplain-semi-join-1.gif)<!-- --> ![](man/figures/tidyexplain-semi-join-1.gif)<!-- -->


``` r ``` r
semi_join(x, y, by = "id")
dplyr::semi_join(x, y, by = "id")
#> # A tibble: 2 x 2 #> # A tibble: 2 x 2
#> id x #> id x
#> <int> <chr> #> <int> <chr>
![](man/figures/tidyexplain-anti-join-1.gif)<!-- --> ![](man/figures/tidyexplain-anti-join-1.gif)<!-- -->


``` r ``` r
anti_join(x, y, by = "id")
dplyr::anti_join(x, y, by = "id")
#> # A tibble: 1 x 2 #> # A tibble: 1 x 2
#> id x #> id x
#> <int> <chr> #> <int> <chr>
## Set Operations ## Set Operations


``` r ``` r
x <- data_frame(
x <- dplyr::data_frame(
x = c(1, 1, 2), x = c(1, 1, 2),
y = c("a", "b", "a") y = c("a", "b", "a")
) )
y <- data_frame(
y <- dplyr::data_frame(
x = c(1, 2), x = c(1, 2),
y = c("a", "b") y = c("a", "b")
) )
![](man/figures/tidyexplain-union-1.gif)<!-- --> ![](man/figures/tidyexplain-union-1.gif)<!-- -->


``` r ``` r
union(x, y)
dplyr::union(x, y)
#> # A tibble: 4 x 2 #> # A tibble: 4 x 2
#> x y #> x y
#> <dbl> <chr> #> <dbl> <chr>


``` r ``` r


union(y, x)
dplyr::union(y, x)
#> # A tibble: 4 x 2 #> # A tibble: 4 x 2
#> x y #> x y
#> <dbl> <chr> #> <dbl> <chr>
![](man/figures/tidyexplain-union-all-1.gif)<!-- --> ![](man/figures/tidyexplain-union-all-1.gif)<!-- -->


``` r ``` r
union_all(x, y)
dplyr::union_all(x, y)
#> # A tibble: 5 x 2 #> # A tibble: 5 x 2
#> x y #> x y
#> <dbl> <chr> #> <dbl> <chr>
![](man/figures/tidyexplain-intersect-1.gif)<!-- --> ![](man/figures/tidyexplain-intersect-1.gif)<!-- -->


``` r ``` r
intersect(x, y)
dplyr::intersect(x, y)
#> # A tibble: 1 x 2 #> # A tibble: 1 x 2
#> x y #> x y
#> <dbl> <chr> #> <dbl> <chr>
![](man/figures/tidyexplain-setdiff-1.gif)<!-- --> ![](man/figures/tidyexplain-setdiff-1.gif)<!-- -->


``` r ``` r
setdiff(x, y)
dplyr::setdiff(x, y)
#> # A tibble: 2 x 2 #> # A tibble: 2 x 2
#> x y #> x y
#> <dbl> <chr> #> <dbl> <chr>


``` r ``` r


setdiff(y, x)
dplyr::setdiff(y, x)
#> # A tibble: 1 x 2 #> # A tibble: 1 x 2
#> x y #> x y
#> <dbl> <chr> #> <dbl> <chr>
you organize your data into tidy data. you organize your data into tidy data.


``` r ``` r
library(tidyr)

long <- data_frame(
long <- dplyr::data_frame(
year = c(2010, 2011, 2010, 2011, 2010, 2011), year = c(2010, 2011, 2010, 2011, 2010, 2011),
person = c("Alice", "Alice", "Bob", "Bob", "Charlie", "Charlie"), person = c("Alice", "Alice", "Bob", "Bob", "Charlie", "Charlie"),
sales = c(105, 110, 100, 97, 90, 95) sales = c(105, 110, 100, 97, 90, 95)
) )
wide <- data_frame(
wide <- dplyr::data_frame(
year = 2010:2011, year = 2010:2011,
Alice = c(105, 110), Alice = c(105, 110),
Bob = c(100, 97), Bob = c(100, 97),
![](man/figures/tidyexplain-gather-1.gif)<!-- --> ![](man/figures/tidyexplain-gather-1.gif)<!-- -->


``` r ``` r
gather(wide, key = "person", value = "sales", -year)
tidyr::gather(wide, key = "person", value = "sales", -year)
#> # A tibble: 6 x 3 #> # A tibble: 6 x 3
#> year person sales #> year person sales
#> <int> <chr> <dbl> #> <int> <chr> <dbl>
![](man/figures/tidyexplain-spread-1.gif)<!-- --> ![](man/figures/tidyexplain-spread-1.gif)<!-- -->


``` r ``` r
spread(long, key = "person", value = "sales")
tidyr::spread(long, key = "person", value = "sales")
#> # A tibble: 2 x 4 #> # A tibble: 2 x 4
#> year Alice Bob Charlie #> year Alice Bob Charlie
#> <dbl> <dbl> <dbl> <dbl> #> <dbl> <dbl> <dbl> <dbl>

読み込み中…
キャンセル
保存