
map_if()
maps a function over the elements of .x
satisfying a predicate. map_at()
is similar but will modify
the elements corresponding to a character vector of names or a
mumeric vector of positions.map_if(.x, .p, .f, ...)map_at(.x, .at, .f, ...)
.x
.
Alternatively, if the elements of .x
are themselves lists of
objects, a string indicating the name of a loIf a function, it is used as is.
If a formula, e.g. ~ .x + 2
, it is converted to a function with
a three arguments, .x
or .
, .y
, .z
. This allows
you
.f
..at
will be
modified..x
.list(x = rbernoulli(100), y = 1:100) %>%
zip_n() %>%
map_if("x", ~ update_list(., y = ~ y * 100)) %>%
zip_n(.simplify = TRUE)
# Convert factors to characters
iris %>%
map_if(is.factor, as.character) %>%
str()
# Specify which columns to map with a numeric vector of positions:
mtcars %>% map_at(c(1, 4, 5), as.character) %>% str()
# Or with a vector of names:
mtcars %>% map_at(c("cyl", "am"), as.character) %>% str()
Run the code above in your browser using DataLab