[R] Substitutions in strings.
ripley at stats.ox.ac.uk
Mon Jul 1 16:00:04 CEST 2002
On Mon, 1 Jul 2002, Fredrik Karlsson wrote:
> Hi all,
> Sorry to bother you with the potentially not too bright question, but
> since I cannot get it to work, I'll have to ask someone..
> I've got this vector:
That's not a vector (or it would be printed with quotes). My guess is
that it is a factor, Try as.character(token).
> > token
>  sal skal skal bak b_r d_ gal kal l_r n_r pak
>  sal sl_r sn_r spak sp_r st_r s_ bak d_ gal l_r
>  p_r sak sl_r sp_r t_ kal n_r s_ st_r sak kal
>  s_ spik t_ n_r spik spak gal pak p_r sak sl_r
>  s_ s_r t_ b_r s_r bak d_ l_r skal sp_r
> sl_r sal
>  st_r n_r bak b_r d_ l_r n_r pak p_r sal
> skal sl_r
>  sn_r spak sp_r st_r s_ s_r t_ bak d_ l_r
> pak p_r
>  sl_r sn_r spak spik s_r t_ gal kal gal n_r
> kal spik
>  n_r n_r bak b_r d_ gal l_r sak sal skal
> sl_r sn_r
>  spik sp_r st_r s_ s_r gal kal n_r sak kal
> pak p_r
> What I whant to do is to substitute all the '_'s in the vector whith
> some other character.
> Trying it out, this works.
>  "A" "AaA"
> However, this does not..
> Error in gsub(pattern, replacement, x, ignore.case, extended) :
> invalid argument
> Can't see why. Please help me out..
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help