Difference between the lmap and map

Hi, Recently i go through the purrr cheat-sheet

I am not getting the exact difference between the

map ,lmap and imap

As mention in cheat-sheet

map using Apply a function to the each list of elements.
lmap using Apply a function to each list-element of a list or vector.

In the sense we apply the lmap list of list of vector?

Correct me if i wrong.

1 Like

With map functions you want to think about the input type and the output type. Some functions (e.g. map()) are more "generic" than others (e.g. map_lgl(), map_int(), etc., which return vectors of their corresponding types).

The difference between the map(), map_at(), and map_if() family and their lmap() counterparts is that the latter

operate exclusively on functions that take and return a list (or data frame)

The imap() family applies a function to each element of a vector and its index. Taking from the docs below:

imap_xxx(x, ...), an indexed map, is short hand for map2(x, names(x), ...) if x has names, or map2(x, seq_along(x), ...) if it does not. This is useful if you need to compute on both the value and the position of an element.

4 Likes