tran | R Documentation |
This should return something like 'to' whenever all of 'x' is in 'from' Otherwise, if some of x is not modified then it needs to either to change those to NAs or to leave them as is. For a strict function, we can simply index to which will leave it unchanged which conflicts with my versions of tr, ergo this is called tran
tr
changes the order of arguments in tran
.
tran(from, to, x, tofactor = is.factor(x))
tr(x, from, to)
from |
numerical, logical or character vector of values or factor levels to change |
to |
vector of corresponding values to change into |
x |
numeric, logical, character vector or factor to modify |
tofactor |
if TRUE, value will be a factor, default: |
tran(FALSE, TRUE, c(FALSE, TRUE, NA))
tran(c(FALSE, NA), c(TRUE, FALSE), c(FALSE, TRUE, NA))
tran(c(FALSE, NA), c(TRUE, FALSE), c(FALSE, TRUE, NA)) %>% mode
# numeric
tran(c(1,2), c(11,12), 1:5)
tran(NA, 99, c(1:5, NA))
tran(NA, 99, c(1:5, NA)) %>% mode
# mixed
tran(c(1,2,10), c('a','b', 'z'), 1:5)
# factor
tran(letters, 1:26, factor(c('a','b','z')) )
tran('a', 1, factor(c('a','b','z')) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.