[R] replacing "+" in string

peter dalgaard pdalgd at gmail.com
Sun Jan 22 19:45:10 CET 2012


On Jan 21, 2012, at 23:04 , Sarah Goslee wrote:

> + is a metacharacter, and must be escaped:
> 
>> X <- "one + two"
>> gsub("\\+", "plus", X)
> [1] "one plus two"
> 
> The help for gsub() tells you to read ?regexp - that's where
> the details of regular expressions as implemented in R are
> explained.
> 

...and it also tells you about the 'fixed' argument:

> X <- "one + two"
> gsub("+", "plus", X, fixed=TRUE)
[1] "one plus two"

-pd
-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list