26.5 The map functions

  • map(.x, .f, ...) makes a list.

  • map_lgl(.x, .f, ...) makes a logical vector.

  • map_int(.x, .f, ...) makes an integer vector.

  • map_dbl(.x, .f, ...) makes a double vector.

  • map_chr(.x, .f, ...) makes a character vector.

Shortcuts with purrr:

  • a one-sided formula creates an anonymous function

  • use a string to extract named components

  • Use an integer to select elements by position

Base R:

  • lapply(X, FUN, ...) makes a list (map is more consistent)

  • sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE) wrapper around lapply

  • vapply(X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE) safe alternative to sapply, can make a matix