translate.RdUses the UNIX tr command to translate any character in old in
text to the corresponding character in new. If multichar=T
or old and new have more than one element, or each have one element
but they have different numbers of characters,
uses the UNIX sed command to translate the series of characters in
old to the series in new when these characters occur in text.
If old or new contain a backslash, you sometimes have to quadruple
it to make the UNIX command work. If they contain a forward slash,
preceed it by two backslashes. Invokes the builtin chartr function if
multichar=FALSE.
translate(text, old, new, multichar=FALSE)an object like text but with characters translated
grep
translate(c("ABC","DEF"),"ABCDEFG", "abcdefg")
#> [1] "abc" "def"
translate("23.12","[.]","\\cdot ") # change . to \cdot
#> [1] "23\004ot 12"
translate(c("dog","cat","tiger"),c("dog","cat"),c("DOG","CAT"))
#> [1] "DOG" "CAT" "tiger"
# S-Plus gives [1] "DOG" "CAT" "tiger" - check discrepency
translate(c("dog","cat2","snake"),c("dog","cat"),"animal")
#> [1] "animal" "animal2" "snake"
# S-Plus gives [1] "animal" "animal2" "snake"