View source: R/multiCharReplace.R
multiCharReplace | R Documentation |
This functions allows multiple types of replacements of entire character elements in simple vector, matrix or data.frame. In addtion, the result may be optionally directly transformed to logical or numeric
multiCharReplace(
mat,
repl,
convTo = NULL,
silent = FALSE,
debug = TRUE,
callFrom = NULL
)
mat |
(character vector, matrix or data.frame) main data |
repl |
(matrix or list) tells what to replace by what: If matrix the 1st oolumn will be considered as 'old' and the 2nd as 'replaceBy'; if named list, the names of the list-elements will be consdered as 'replaceBy' |
convTo |
(character) optional conversion of content to 'numeric' or 'logical' |
silent |
(logical) suppress messages |
debug |
(logical) additional messages for debugging |
callFrom |
(character) allow easier tracking of messages produced |
This function returns an object of same dimension as input (with replaced content)
grep
x1 <- c("ab","bc","cd","efg","ghj")
multiCharReplace(x1, cbind(old=c("bc","efg"), new=c("BBCC","EF")))
x2 <- c("High","n/a","High","High","Low")
multiCharReplace(x2, cbind(old=c("n/a","Low","High"), new=c(NA,FALSE,TRUE)),convTo="logical")
# works also to replace numeric content :
x3 <- matrix(11:16, ncol=2)
multiCharReplace(x3, cbind(12:13,112:113))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.