decipher | R Documentation |
Change values that corresponds to those of a key.
decipher(x, key, flexible = TRUE, within = FALSE)
translate(x, key, flexible = TRUE, within = FALSE)
x |
Character (or factor) vector |
key |
Named character vector; where (typically) the names corresponds
to values appearing in x, and the values are those we want as
replacements. However, if |
flexible |
Logical; if TRUE the key can be inverted |
within |
Logical; if TRUE occurences of the keyed values within a string can be replaced. Such occurences must be encapsulated by beginning of line, space characters, punctuation characters or end of line, so that replacement does not take place within words. |
vector of same length and class as s (character or factor)
x <- c("foo", "foo!", "A foo", "A foo and two bar",
"football", "barely", "bar")
key <- c(foo = "yay", bar = "bohnanza")
data.frame(
x = x,
d0 = key[x], ## useful only if all values of s exists in the key
d1 = decipher(x, key),
d2 = decipher(x, key, within = TRUE)
)
x <- factor(c(1,3,2), levels = 1:3,
labels = c("foo", "bar", "baz"))
key <- c(A = "foo", C = "baz")
str(data.frame(x = x, d = decipher(x, key)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.