The functions map_if()
and map_at()
take .x
as input, apply
the function .f
to some of the elements of .x
, and return a
list of the same length as the input.
map_if()
takes a predicate function .p
as input to determine
which elements of .x
are transformed with .f
.
map_at()
takes a vector of names or positions .at
to specify
which elements of .x
are transformed with .f
.
map_depth()
allows to apply .f
to a specific
depth level of a nested vector.
map_if(.x, .p, .f, ..., .else = NULL) map_at(.x, .at, .f, ...) map_depth(.x, .depth, .f, ..., .ragged = FALSE)
.x | A list or atomic vector. |
---|---|
.p | A single predicate function, a formula describing such a
predicate function, or a logical vector of the same length as |
.f | A function, formula, or vector (not necessarily atomic). If a function, it is used as is. If a formula, e.g.
This syntax allows you to create very compact anonymous functions. If character vector, numeric vector, or list, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of |
... | Additional arguments passed on to the mapped function. |
.else | A function applied to elements of |
.at | A character vector of names, positive numeric vector of
positions to include, or a negative numeric vector of positions to
exlude. Only those elements corresponding to |
.depth | Level of
|
.ragged | If |
# Use a predicate function to decide whether to map a function: map_if(iris, is.factor, as.character)#> $Sepal.Length #> [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4 5.1 #> [19] 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5 4.9 5.0 #> [37] 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6 5.3 5.0 7.0 6.4 6.9 5.5 #> [55] 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1 5.6 6.7 5.6 5.8 6.2 5.6 5.9 6.1 #> [73] 6.3 6.1 6.4 6.6 6.8 6.7 6.0 5.7 5.5 5.5 5.8 6.0 5.4 6.0 6.7 6.3 5.6 5.5 #> [91] 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2 5.1 5.7 6.3 5.8 7.1 6.3 6.5 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8 2.2 2.3 1.5 2.3 2.0 2.0 1.8 2.1 1.8 #> [127] 1.8 1.8 2.1 1.6 1.9 2.0 2.2 1.5 1.4 2.3 2.4 1.8 1.8 2.1 2.4 2.3 1.9 2.3 #> [145] 2.5 2.3 1.9 2.0 2.3 1.8 #> #> $Species #> [1] "setosa" "setosa" "setosa" "setosa" "setosa" #> [6] "setosa" "setosa" "setosa" "setosa" "setosa" #> [11] "setosa" "setosa" "setosa" "setosa" "setosa" #> [16] "setosa" "setosa" "setosa" "setosa" "setosa" #> [21] "setosa" "setosa" "setosa" "setosa" "setosa" #> [26] "setosa" "setosa" "setosa" "setosa" "setosa" #> [31] "setosa" "setosa" "setosa" "setosa" "setosa" #> [36] "setosa" "setosa" "setosa" "setosa" "setosa" #> [41] "setosa" "setosa" "setosa" "setosa" "setosa" #> [46] "setosa" "setosa" "setosa" "setosa" "setosa" #> [51] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [56] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [61] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [66] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [71] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [76] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [81] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [86] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [91] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [96] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [101] "virginica" "virginica" "virginica" "virginica" "virginica" #> [106] "virginica" "virginica" "virginica" "virginica" "virginica" #> [111] "virginica" "virginica" "virginica" "virginica" "virginica" #> [116] "virginica" "virginica" "virginica" "virginica" "virginica" #> [121] "virginica" "virginica" "virginica" "virginica" "virginica" #> [126] "virginica" "virginica" "virginica" "virginica" "virginica" #> [131] "virginica" "virginica" "virginica" "virginica" "virginica" #> [136] "virginica" "virginica" "virginica" "virginica" "virginica" #> [141] "virginica" "virginica" "virginica" "virginica" "virginica" #> [146] "virginica" "virginica" "virginica" "virginica" "virginica" #># Specify an alternative with the `.else` argument: map_if(iris, is.factor, as.character, .else = as.integer)#> $Sepal.Length #> [1] 5 4 4 4 5 5 4 5 4 4 5 4 4 4 5 5 5 5 5 5 5 5 4 5 4 5 5 5 5 4 4 5 5 5 4 5 5 #> [38] 4 4 5 5 4 4 5 5 4 5 4 5 5 7 6 6 5 6 5 6 4 6 5 5 5 6 6 5 6 5 5 6 5 5 6 6 6 #> [75] 6 6 6 6 6 5 5 5 5 6 5 6 6 6 5 5 5 6 5 5 5 5 5 6 5 5 6 5 7 6 6 7 4 7 6 7 6 #> [112] 6 6 5 5 6 6 7 7 6 6 5 7 6 6 7 6 6 6 7 7 7 6 6 6 7 6 6 6 6 6 6 5 6 6 6 6 6 #> [149] 6 5 #> #> $Sepal.Width #> [1] 3 3 3 3 3 3 3 3 2 3 3 3 3 3 4 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 3 3 3 #> [38] 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 2 2 2 3 2 2 2 2 3 2 2 2 3 3 2 2 2 3 2 2 2 #> [75] 2 3 2 3 2 2 2 2 2 2 3 3 3 2 3 2 2 3 2 2 2 3 2 2 2 2 3 2 3 2 3 3 2 2 2 3 3 #> [112] 2 3 2 2 3 3 3 2 2 3 2 2 2 3 3 2 3 2 3 2 3 2 2 2 3 3 3 3 3 3 3 2 3 3 3 2 3 #> [149] 3 3 #> #> $Petal.Length #> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 #> [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 3 4 3 3 4 4 4 3 4 4 4 4 3 4 4 4 4 #> [75] 4 4 4 5 4 3 3 3 3 5 4 4 4 4 4 4 4 4 4 3 4 4 4 4 3 4 6 5 5 5 5 6 4 6 5 6 5 #> [112] 5 5 5 5 5 5 6 6 5 5 4 6 4 5 6 4 4 5 5 6 6 5 5 5 6 5 5 4 5 5 5 5 5 5 5 5 5 #> [149] 5 5 #> #> $Petal.Width #> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #> [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 #> [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 2 1 1 1 2 2 #> [112] 1 2 2 2 2 1 2 2 1 2 2 2 1 2 1 1 1 2 1 1 2 2 1 1 2 2 1 1 2 2 2 1 2 2 2 1 2 #> [149] 2 1 #> #> $Species #> [1] "setosa" "setosa" "setosa" "setosa" "setosa" #> [6] "setosa" "setosa" "setosa" "setosa" "setosa" #> [11] "setosa" "setosa" "setosa" "setosa" "setosa" #> [16] "setosa" "setosa" "setosa" "setosa" "setosa" #> [21] "setosa" "setosa" "setosa" "setosa" "setosa" #> [26] "setosa" "setosa" "setosa" "setosa" "setosa" #> [31] "setosa" "setosa" "setosa" "setosa" "setosa" #> [36] "setosa" "setosa" "setosa" "setosa" "setosa" #> [41] "setosa" "setosa" "setosa" "setosa" "setosa" #> [46] "setosa" "setosa" "setosa" "setosa" "setosa" #> [51] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [56] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [61] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [66] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [71] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [76] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [81] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [86] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [91] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [96] "versicolor" "versicolor" "versicolor" "versicolor" "versicolor" #> [101] "virginica" "virginica" "virginica" "virginica" "virginica" #> [106] "virginica" "virginica" "virginica" "virginica" "virginica" #> [111] "virginica" "virginica" "virginica" "virginica" "virginica" #> [116] "virginica" "virginica" "virginica" "virginica" "virginica" #> [121] "virginica" "virginica" "virginica" "virginica" "virginica" #> [126] "virginica" "virginica" "virginica" "virginica" "virginica" #> [131] "virginica" "virginica" "virginica" "virginica" "virginica" #> [136] "virginica" "virginica" "virginica" "virginica" "virginica" #> [141] "virginica" "virginica" "virginica" "virginica" "virginica" #> [146] "virginica" "virginica" "virginica" "virginica" "virginica" #>#> $Sepal.Length #> [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4 5.1 #> [19] 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5 4.9 5.0 #> [37] 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6 5.3 5.0 7.0 6.4 6.9 5.5 #> [55] 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1 5.6 6.7 5.6 5.8 6.2 5.6 5.9 6.1 #> [73] 6.3 6.1 6.4 6.6 6.8 6.7 6.0 5.7 5.5 5.5 5.8 6.0 5.4 6.0 6.7 6.3 5.6 5.5 #> [91] 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2 5.1 5.7 6.3 5.8 7.1 6.3 6.5 7.6 4.9 7.3 #> [109] 6.7 7.2 6.5 6.4 6.8 5.7 5.8 6.4 6.5 7.7 7.7 6.0 6.9 5.6 7.7 6.3 6.7 7.2 #> [127] 6.2 6.1 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7 6.3 6.4 6.0 6.9 6.7 6.9 5.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 #> [73] 4.9 4.7 4.3 4.4 4.8 5.0 4.5 3.5 3.8 3.7 3.9 5.1 4.5 4.5 4.7 4.4 4.1 4.0 #> [91] 4.4 4.6 4.0 3.3 4.2 4.2 4.2 4.3 3.0 4.1 6.0 5.1 5.9 5.6 5.8 6.6 4.5 6.3 #> [109] 5.8 6.1 5.1 5.3 5.5 5.0 5.1 5.3 5.5 6.7 6.9 5.0 5.7 4.9 6.7 4.9 5.7 6.0 #> [127] 4.8 4.9 5.6 5.8 6.1 6.4 5.6 5.1 5.6 6.1 5.6 5.5 4.8 5.4 5.6 5.1 5.1 5.9 #> [145] 5.7 5.2 5.0 5.2 5.4 5.1 #> #> $Petal.Width #> [1] TRUE #> #> $Species #> [1] FALSE #># Use vector of names to specify which elements to change: iris %>% map_at("Species", toupper)#> $Sepal.Length #> [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 4.8 4.3 5.8 5.7 5.4 5.1 #> [19] 5.7 5.1 5.4 5.1 4.6 5.1 4.8 5.0 5.0 5.2 5.2 4.7 4.8 5.4 5.2 5.5 4.9 5.0 #> [37] 5.5 4.9 4.4 5.1 5.0 4.5 4.4 5.0 5.1 4.8 5.1 4.6 5.3 5.0 7.0 6.4 6.9 5.5 #> [55] 6.5 5.7 6.3 4.9 6.6 5.2 5.0 5.9 6.0 6.1 5.6 6.7 5.6 5.8 6.2 5.6 5.9 6.1 #> [73] 6.3 6.1 6.4 6.6 6.8 6.7 6.0 5.7 5.5 5.5 5.8 6.0 5.4 6.0 6.7 6.3 5.6 5.5 #> [91] 5.5 6.1 5.8 5.0 5.6 5.7 5.7 6.2 5.1 5.7 6.3 5.8 7.1 6.3 6.5 7.6 4.9 7.3 #> [109] 6.7 7.2 6.5 6.4 6.8 5.7 5.8 6.4 6.5 7.7 7.7 6.0 6.9 5.6 7.7 6.3 6.7 7.2 #> [127] 6.2 6.1 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7 6.3 6.4 6.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#> #> $Species #> [1] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [6] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [11] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [16] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [21] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [26] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [31] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [36] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [41] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [46] "SETOSA" "SETOSA" "SETOSA" "SETOSA" "SETOSA" #> [51] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [56] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [61] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [66] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [71] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [76] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [81] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [86] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [91] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [96] "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" "VERSICOLOR" #> [101] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [106] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [111] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [116] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [121] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [126] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [131] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [136] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [141] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #> [146] "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" "VIRGINICA" #># Use `map_depth()` to recursively traverse nested vectors and map # a function at a certain depth: x <- list(a = list(foo = 1:2, bar = 3:4), b = list(baz = 5:6)) str(x)#> List of 2 #> $ a:List of 2 #> ..$ foo: int [1:2] 1 2 #> ..$ bar: int [1:2] 3 4 #> $ b:List of 1 #> ..$ baz: int [1:2] 5 6map_depth(x, 2, paste, collapse = "/")#> $a #> $a$foo #> [1] "1/2" #> #> $a$bar #> [1] "3/4" #> #> #> $b #> $b$baz #> [1] "5/6" #> #>#> $a #> $a$foo #> [1] "1/2" #> #> $a$bar #> [1] "3/4" #> #> #> $b #> $b$baz #> [1] "5/6" #> #>