replace_head: replace_head

View source: R/replace_head.R

replace_headR Documentation

replace_head

Description

Replace initial n values in a vector.

Usage

replace_head(v, n, r)

Arguments

v

vector. Input vector to have head replaced.

n

integer. Number of values at start of v to replace. If left NULL, this will be calculated as the length of r.

r

String, logical, numeric etc. What to use as replacement. Should either be a single value or vector of length n.

Details

A simple solution for replacing the initial n values in a vector. Replacing the initial n values is straightforward compared to replacing the final n values, but this makes a nice partner function to replace_head().

Value

The v vector is returned but with the initial n values overwritten by 'r.

Author(s)

Nicholas Carey - nicholascarey@gmail.com

See Also

replace_head

Examples

# Replace initial 5 numeric values with single value
x <- 1:10
replace_head(x, 5, 100)

# Replace initial logical with a different logical
x <- rep(TRUE, 10)
replace_head(x, 1, FALSE)

# Replace initial n with a vector of same length
x <- 1:20
replace_head(x, 5, c(100,99,98,97,96))


nicholascarey/caRey documentation built on Sept. 30, 2023, 3:47 a.m.