I know how purrr effectively replaces the {l,v,s,m}apply functionals, but I wonder about the apply function itself. I can see how if we have a 2d array what is done by apply when MARGIN=2, could be done by purrr::map_dbl or even dplyr::summarize_all, and when MARGIN=1, this could be done by purrr:pmap.
library(purrr)
library(tibble)
library(dplyr)
set.seed(123)
n <- 5
Df <- tibble(x = rnorm(n), y = rnorm(n), z = rnorm(n))
apply(Df, 2, sum)
x y z
0.9678513 -0.2215949 1.5395087
map_dbl(Df, sum)
x y z
0.9678513 -0.2215949 1.5395087
summarise_all(Df, sum)
# A tibble: 1 x 3
x y z
<dbl> <dbl> <dbl>
1 0.968 -0.222 1.54
apply(Df, 1, sum)
[1] 2.3786711 0.5905525 0.6944185 -0.5056617 -0.8722154
pmap_dbl(Df, sum)
[1] 2.3786711 0.5905525 0.6944185 -0.5056617 -0.8722154
But is there a purrr way to do the following for example?
> apply(Titanic, c(2, 3), sum)
Age
Sex Child Adult
Male 64 1667
Female 45 425