I thought the idea of the .id
parameter to map2_dfr
was supposed to provide a variable name:
but that doesn't work with my example (reprex below):
library(purrr)
lows <- 1:7 %>%
`*`(10) %>%
`+`(5)
highs <- rep(9, 6) %>%
c(., 15) %>%
map2_dbl(lows, `+`)
# I want this vector, but as a 1-column tibble:
purrr::map2_chr(lows, highs, ~ paste0(.x, "-", .y))
#> [1] "15-24" "25-34" "35-44" "45-54" "55-64" "65-74" "75-90"
purrr::map2_dfr(lows, highs, ~ paste0(.x, "-", .y), .id = "age_group")
#> Error: Argument 1 must have names.
Created on 2021-06-21 by the reprex package (v2.0.0)
I could add an extra line and use tibble::enframe
or similar to get the result I want, but I would like to understand what is wrong with the more compact map2_dfr
approach I'm trying to use. Why is the .id
parameter not providing a column name and preventing the error?