Skip to content

Commit

Permalink
Data frame examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Oct 24, 2019
1 parent def4418 commit 4374198
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ A neat (but fairly inefficient) way to interleave vectors
flat_map2_dbl(1:5, 6:10, ~c(.x, .y))
```

With data frames

```{r}
flat_map_dfr(list(1, 2:3, 4:6), ~data.frame(x = .x))
flat_map_dfc(
list(1, 2:3, 4, 5:6),
~{
name <- paste0("x_", paste0(.x, collapse = "_"))
tibble::tibble(!! name := .x)
}
)
```

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@ A neat (but fairly inefficient) way to interleave vectors
flat_map2_dbl(1:5, 6:10, ~c(.x, .y))
#> [1] 1 6 2 7 3 8 4 9 5 10
```

With data frames

``` r
flat_map_dfr(list(1, 2:3, 4:6), ~data.frame(x = .x))
#> x
#> 1 1
#> 2 2
#> 3 3
#> 4 4
#> 5 5
#> 6 6

flat_map_dfc(
list(1, 2:3, 4, 5:6),
~{
name <- paste0("x_", paste0(.x, collapse = "_"))
tibble::tibble(!! name := .x)
}
)
#> x_1 x_2_3 x_4 x_5_6
#> 1 1 2 4 5
#> 2 1 3 4 6
```

0 comments on commit 4374198

Please sign in to comment.