using purrr to extract elements from multiple lists starting with a common letter
问题 I have a list of lists. One element in each list has a name beginning with "n_". How do I extract these elements and store them in a separate list? Can I use a combination of map and starts_with ? E.g.: m1 <- list(n_age = c(19,40,39), names = c("a", "b", "c")) m2 <- list(n_gender = c("m","f","f"), names = c("f", "t", "d")) nice_list <- list(m1, m2) I was hoping that something like the following to work (it doesn't!): output <- map(nice_list, starts_with("n_")) 回答1: How about this? map(nice