Re: [R] replacing "+" in string

2012-01-22 Thread peter dalgaard
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 > expla

Re: [R] replacing "+" in string

2012-01-21 Thread Sarah Goslee
+ 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. Sarah On Sat, Jan 21, 2012 at 2:46 PM, Nevil Amos wrote:

Re: [R] replacing "+" in string

2012-01-21 Thread R. Michael Weylandt
Two ways: i) (If you are not using full regular expressions) Set the fixed = TRUE option. ii) Escape it. E.g., gsub("\\+", "plus", X) gsub("+", "plus", X, fixed = TRUE) Read up on ?regexp for an explanation of what's going on. Michael On Sat, Jan 21, 2012 at 2:46 PM, Nevil Amos wrote: > I a

[R] replacing "+" in string

2012-01-21 Thread Nevil Amos
I am trying to replace "+" in a string with another character I am getting odd results using sub and gsub > X<-"one + two" > gsub("+","plus",X) [1] "plusoplusnpluseplus plus+plus plustpluswplusoplus" > sub("+","plus",X) [1] "plusone + two" > X<-"one ~ two" it seems to work fine with other charact