translate               package:Hmisc               R Documentation

_T_r_a_n_s_l_a_t_e _V_e_c_t_o_r _o_r _M_a_t_r_i_x _o_f _T_e_x_t _S_t_r_i_n_g_s

_D_e_s_c_r_i_p_t_i_o_n:

     Uses 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.  The Microsoft
     Windows version of 'translate' invokes the 'sedit()' function and
     does not allow 'multichar=FALSE', i.e., it does not support the
     UNIX 'tr' function. The R version of 'translate' invokes the
     builtin chartr function if 'multichar=FALSE'.

_U_s_a_g_e:

     translate(text, old, new, multichar=FALSE)

_A_r_g_u_m_e_n_t_s:

    text: scalar, vector, or matrix of character strings to translate. 

     old: vector old characters 

     new: corresponding vector of new characters 

multichar: See above.

_D_e_t_a_i_l_s:

     At present, 'multichar=FALSE', which requires the UNIX 'tr'
     program, is not implemented under MS Windows.

_V_a_l_u_e:

     an object like text but with characters translated

_S_e_e _A_l_s_o:

     unix, grep

_E_x_a_m_p_l_e_s:

     translate(c("ABC","DEF"),"ABCDEFG", "abcdefg")
     translate("23.12","[.]","\\\cdot ") # change . to \cdot
     translate(c("dog","cat","tiger"),c("dog","cat"),c("DOG","CAT"))
     # S-Plus gives  [1] "DOG"   "CAT"   "tiger" - check discrepency
     translate(c("dog","cat2","snake"),c("dog","cat"),"animal")
     # S-Plus gives  [1] "animal"  "animal2" "snake" 

