substr                 package:base                 R Documentation

_E_x_t_r_a_c_t _S_u_b_s_t_r_i_n_g_s _f_r_o_m _a _C_h_a_r_a_c_t_e_r _V_e_c_t_o_r

_D_e_s_c_r_i_p_t_i_o_n:

     Extract substrings from a character vector returning a vector
     whose elements contain the substring starting with the character
     at position `start' up to the character at position `stop'.

_U_s_a_g_e:

     substr(x, start, stop)
     substring(text, first, last = 1000000)

_D_e_t_a_i_l_s:

     If `start' is larger than the string length then `NA' is returned.
     If `stop' is longer than `start' an error is signalled.

     `substring' is compatible with S, with `first' and `last' instead
     of `start' and `stop'. For vector arguments, it expands the
     arguments cyclically.

_S_e_e _A_l_s_o:

     `strsplit', `paste', `nchar'.

_E_x_a_m_p_l_e_s:

     substr("abcdef",2,4)
     print(ss <- substring("abcdef",1:6,1:6))
     stopifnot(ss == strsplit ("abcdef",NULL)[[1]])# strsplit is more efficient..

     substr(rep("abcdef",4),1:4,4:5)
     x <- c("asfef", "qwerty", "yuiop[", "b", "stuff.blah.yech")
     stopifnot(substr(x, 2, 5) == substring(x, 2, 5))
     substr(x, 2, 5)
     substring(x, 2, 4:6)

