search_replace: Search and Replace

View source: R/search_replace.R

search_replaceR Documentation

Search and Replace

Description

A global search & replace of entries within a vector, matrix, or data frame Note: The lengths of s and r must be identical.

Usage

search_replace(x, s, r)

Arguments

x

The object to be searched, typically a matrix or data frame but can be a vector of character or numeric class.

s

The search index.

r

The replace with. Must be same length as s.

Value

An object of the same dimensions and class as x, with the s matches replaced with r.

Author(s)

Stu Field

Examples

# matrix
Y <- matrix(1:25, ncol = 5)
Y
search_replace(Y, s = c(8, 20), r = c(99, 99))

# data.frame
X <- data.frame(x = c(1, 2, 3), y = c(2, 2, 4), z = c(1, 2, 4))
rownames(X) <- c("one", "two", "three")
X
search_replace(X, s = 1:4, r = c("A", "C", "G", "T"))

# numeric
search_replace(1:10, s = 4, r = 19)

# character
search_replace(head(LETTERS, 10), s = "G", r = "Z")

stufield/stuRpkg documentation built on April 2, 2022, 2:05 p.m.