multiCharReplace: Multiple replacement of entire character elements in simple...

View source: R/multiCharReplace.R

multiCharReplaceR Documentation

Multiple replacement of entire character elements in simple vector, matrix or data.frame

Description

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

Usage

multiCharReplace(
  mat,
  repl,
  convTo = NULL,
  silent = FALSE,
  debug = TRUE,
  callFrom = NULL
)

Arguments

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

Value

This function returns an object of same dimension as input (with replaced content)

See Also

grep

Examples

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))

wrMisc documentation built on Sept. 11, 2024, 6:10 p.m.