trim                  package:gdata                  R Documentation

_R_e_m_o_v_e _l_e_a_d_i_n_g _a_n_d _t_r_a_i_l_i_n_g _s_p_a_c_e_s _f_r_o_m _c_h_a_r_a_c_t_e_r _s_t_r_i_n_g_s

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

     Remove leading and trailing spaces from character strings and
     other related objects.

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

     trim(s, recode.factor=TRUE, ...)

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

       s: object to be processed

recode.factor: should levels of a factor be recoded, see below

     ...: arguments passed to other methods, currently only to
          'reorder.factor' for factors

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

     'trim' is a generic function, where default method does nothing,
     while method for character 's' trims its elements and method for
     factor 's' trims 'levels'. There are also methods for 'list' and
     'data.frame'.

     Trimming character strings can change the sort order in some
     locales. For factors, this can affect the coding of levels. By
     default, factor levels are recoded to match the trimmed sort
     order, but this can be disabled by setting 'recode.factor=FALSE'.
     Recoding is done with 'reorder.factor'.

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

     's' with all leading and trailing spaces removed in its elements.

_A_u_t_h_o_r(_s):

     Gregory R. Warnes warnes@bst.rochester.edu  with contributions by
     Gregor Gorjanc

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

     'sub', 'gsub' as well as argument 'strip.white' in 'read.table'
     and 'reorder.factor'

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

     s <- "    this is an example string    "
     trim(s)

     f <- factor(c(s, s, " A", " B ", "  C ", "D "))
     levels(f)

     trim(f)
     levels(trim(f))

     trim(f, recode.factor=FALSE)
     levels(trim(f, recode.factor=FALSE))

     l <- list(s=rep(s, times=6), f=f, i=1:6)
     trim(l)

     df <- as.data.frame(l)
     trim(df)

