Is there a way to automatically give names to the returned list given by purrr:map
?
For example, I run code like this very often.
fn <- function(x) { paste0(x, "_") }
l <- map(LETTERS, fn)
names(l) <- LETTERS
I'd like for the vector that is being automated upon to automatically become the names of the resulting list.
We can use imap
imap(setNames(LETTERS, LETTERS), ~ paste0(.x, "_"))
Or map
with a named vector
map(setNames(LETTERS, LETTERS), ~ paste0(.x, "_"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With