fill: Fill locations in a vectors with a single value

Description Usage Arguments Value

Description

Fill fills in selected indices of that vector with the scalar result of a function applied to that vector. Types are coerced upwards if the fill value is of a different type from the original vector. e.g. logical -> integer -> double -> character.

Usage

1
2
3
fill_if(.x, .p, .f, ...)

fill_at(.x, .at, .f, ...)

Arguments

.x

atomic vector

.p

A single predicate function, a formula describing such a predicate function, or a logical vector of the same length as .x. Alternatively, if the elements of .x are themselves lists of objects, a string indicating the name of a logical element in the inner lists. Only those elements where .p evaluates to TRUE will be modified.

.f

A function, formula, or scalar atomic. Must return a scalar atomic.

If a function, it is used as is.

If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments: For a single argument function, use . For a two argument function, use .x and .y For more arguments, use ..1, ..2, ..3 etc.

This syntax allows you to create very compact anonymous functions.

If scalar character or scalar numeric, it is converted to a formula, which is then converted to a function as above. The end result is that the value is filled in in the selected locations.

...

Additional arguments passed on to .f.

.at

A character vector of names or a numeric vector of positions. Only those elements corresponding to .at will be modified.

Value

atomic vector of same length as .x


biodatacore/biodatacoreUtils documentation built on May 28, 2019, 7:11 p.m.