Searches for a pattern in a vector and replaces it with a provided replacement pattern.

replace_portion(invec, find, replace)

Arguments

invec

The input vector.

find

What is the sequence that you're looking for?

replace

What do you want to replace the values with?

Value

A vector the same length as the input vector.

Author

Ananda Mahto

Examples

x <- c(1, 2, 3, 1, 0, 1, 0, 1, 2, 3, 4, 1, 0, 1) replace_portion(x, c(1, 0, 1), c(9, 9, 9))
#> [1] 1 2 3 9 9 9 0 1 2 3 4 9 9 9