lapply / purrr::map like function that allows access to the index by default?
问题 There's a workaround to allow access the index inside a s/lapply e.g. x <- list(a=11,b=12,c=13) lapply(seq_along(x), function(y, n, i) { paste(n[[i]], y[[i]]) }, y=x, n=names(x)) Is there any function like s/lapply (or like purrr::map() ) which allows access to the index in the simplest way possible, which I guess would be to simply supply its desired name to the initial function call and nothing more; map_with_index <- function(.x, .f, index) { # Same as purrr::map() # ..but whatever string