modify_if

0th

Percentile

Selectively Modify Elements of a Vector

Modifies elements of a vector selectively, similar to the functions in purrr.

modify_if() applies a predicate function .p to all elements of .x and applies .f to those elements of .x where .p evaluates to TRUE.

modify_at() applies .f to those elements of .x selected via .at.

Usage
modify_if(.x, .p, .f, ...)

modify_at(.x, .at, .f, ...)

Arguments
.x

:: vector().

.p

:: function() Predicate function.

.f

:: function() Function to apply on .x.

...

:: any Additional arguments passed to .f.

.at

:: (integer() | character()) Index vector to select elements from .x.

Aliases
  • modify_if
  • modify_at
Examples
# NOT RUN {
x = modify_if(iris, is.factor, as.character)
str(x)

x = modify_at(iris, 5, as.character)
x = modify_at(iris, "Sepal.Length", sqrt)
str(x)
# }
Documentation reproduced from package mlr3misc, version 0.1.0, License: LGPL-3

Community examples

Looks like there are no examples yet.