Trying to learn purrr::map functions, and having trouble with map2 and a function that includes group_by. This could be something elementary that I am doing wrong, but I am not clear on what.

Reprex below

```
#load libraries
library(rlang)
library(tidyverse)
library(fivethirtyeight)
library(purrr)
# make function
mean_grouped <- function(data, groupvar, meanvar) {
data %>%
group_by({{ groupvar }}) %>%
summarise(mean = mean({{ meanvar }}, na.rm = TRUE))
}
# test function
mean_grouped(starwars, homeworld, height)
#> # A tibble: 49 x 2
#> homeworld mean
#> <chr> <dbl>
#> 1 Alderaan 176.
#> 2 Aleen Minor 79
#> 3 Bespin 175
#> 4 Bestine IV 180
#> 5 Cato Neimoidia 191
#> 6 Cerea 198
#> 7 Champala 196
#> 8 Chandrila 150
#> 9 Concord Dawn 183
#> 10 Corellia 175
#> # … with 39 more rows
# try to purrr::map function over possible options for grouping var
# and for mean var
# first create df of all combinations
group_vars = c("gender", "homeworld", "species",
"hair_color", "eye_color", "skin_color")
mean_vars = c("height", "mass", "birth_year")
vars_list <- list(x = group_vars, y = mean_vars)
cross_list <- cross_df(vars_list)
# Now map attempt
starwars %>%
map2_dfr(.x = cross_list$x,
.y = cross_list$y,
.f = mean_grouped)
#> Error in UseMethod("group_by_"): no applicable method for 'group_by_' applied to an object of class "character"
```

^{Created on 2019-06-30 by the reprex package (v0.3.0)}