Re: [R] Search and convert string function

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sun 06 Mar 2005 - 15:46:10 EST

On Sun, 6 Mar 2005, peng shen wrote:

> Hi all,
> I want to do this kind of function In R enviroment :
> For example :
> R <- 4
> testString <- "I love $R"
> then search this testString, when find "$R",replace "$R" to R ,and because
> the value of R is 4
> So the final string I want to get is "I love 4"

> How can I implement? Thanks advance

sub("$R", R, testString, fixed = TRUE)

-- 
Brian D. Ripley,                  ripley@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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sun Mar 06 15:55:20 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:41 EST