recode_by {mark} | R Documentation |
Recode by
Description
A simple implementation of recoding
Usage
recode_by(x, by, vals = NULL, mode = "any")
recode_only(x, by, vals = NULL)
Arguments
x |
A vector to recode |
by |
A names vector ( |
vals |
An optional vector of values to use in lieu of a names in the
vector; this takes priority over |
mode |
passed to |
Details
This can be comparable to dplyr::recode()
expect that the values are
arranged as new = old
rather than old = new
and allows for a separate
vector to be passed for new
.
recode_only()
will only recode the values matches in by
/val
.
The mode
is automatically set according to mode(x)
. This functions
more like base::replace()
but with extra features
Value
A vector of values from x
See Also
Examples
recode_by(1:3, c(a = 1, b = 2))
recode_by(letters[1:3], c(`1` = "a", `2` = "b")) # will not guess mode
recode_by(letters[1:3], c(`1` = "a", `2` = "b"), mode = "integer") # make as integer
recode_by(letters[1:3], c("a", "b"), vals = 1:2) # or pass to vals
recode_only(letters[1:3], c("zzz" = "a"))
recode_only(letters[1:3], c(`1` = "a")) # returns as "1"
recode_only(1:3, c("a" = 1)) # coerced to NA
# Pass list for multiples
recode_only(letters[1:10], list(abc = c("a", "b", "c"), ef = c("e", "f")))
[Package mark version 0.8.0 Index]