I am following an issue posted on github, https://github.com/tidyverse/purrr/issues/179 and found that there is a map inside a map. Can any one explain, what the outer map is doing. Or can we write the . %>%
pipe like map(~mean(.x)
. Any help?
suppressWarnings(library(purrr))
suppressWarnings(library(purrrlyr))
alist <- list(
data.frame(a = 1:2, b = 6:7),
data.frame(a = 3:5, b = 8:10)
)
# using purrr
alist %>% map(. %>% map_dbl(mean)) %>% dplyr::bind_rows()
#> # A tibble: 2 x 2
#> a b
#> <dbl> <dbl>
#> 1 1.5 6.5
#> 2 4 9
## using dmap
alist %>% map_df(. %>% dmap(mean))
#> # A tibble: 2 x 2
#> a b
#> <dbl> <dbl>
#> 1 1.5 6.5
#> 2 4 9
Created on 2020-08-05 by the reprex package (v0.3.0)