View source: R/search_replace.R
search_replace | R Documentation |
A global search & replace of entries within a vector, matrix, or data frame
Note: The lengths of s
and r
must be identical.
search_replace(x, s, r)
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 |
An object of the same dimensions and class as x
, with the
s
matches replaced with r
.
Stu Field
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.