Learn R Programming

tidytable (version 0.11.1)

map: Apply a function to each element of a vector or list

Description

The map functions transform their input by applying a function to each element and returning a list/vector/data.table.

  • map() returns a list

  • _lgl(), _int, _dbl,_chr, _df variants return their specified type

  • _dfr & _dfc Return all data frame results combined utilizing row or column binding

Usage

map(.x, .f, ...)

map_lgl(.x, .f, ...)

map_int(.x, .f, ...)

map_dbl(.x, .f, ...)

map_chr(.x, .f, ...)

map_dfc(.x, .f, ...)

map_dfr(.x, .f, ..., .id = NULL)

map_df(.x, .f, ..., .id = NULL)

walk(.x, .f, ...)

map_vec(.x, .f, ..., .ptype = NULL)

map2(.x, .y, .f, ...)

map2_lgl(.x, .y, .f, ...)

map2_int(.x, .y, .f, ...)

map2_dbl(.x, .y, .f, ...)

map2_chr(.x, .y, .f, ...)

map2_dfc(.x, .y, .f, ...)

map2_dfr(.x, .y, .f, ..., .id = NULL)

map2_df(.x, .y, .f, ..., .id = NULL)

map2_vec(.x, .y, .f, ..., .ptype = NULL)

pmap(.l, .f, ...)

pmap_lgl(.l, .f, ...)

pmap_int(.l, .f, ...)

pmap_dbl(.l, .f, ...)

pmap_chr(.l, .f, ...)

pmap_dfc(.l, .f, ...)

pmap_dfr(.l, .f, ..., .id = NULL)

pmap_df(.l, .f, ..., .id = NULL)

pmap_vec(.l, .f, ..., .ptype = NULL)

Arguments

.x

A list or vector

.f

A function

...

Other arguments to pass to a function

.id

Whether map_dfr() should add an id column to the finished dataset

.ptype

ptype for resulting vector in map_vec()

.y

A list or vector

.l

A list to use in pmap

Examples

Run this code
map(c(1,2,3), ~ .x + 1)

map_dbl(c(1,2,3), ~ .x + 1)

map_chr(c(1,2,3), as.character)

Run the code above in your browser using DataLab