On 23/11/2009, at 12:01 PM, Steven Kang wrote:

Hi all,


I get an error message when trying to replace *+* or *?* signs (with empty
space) from a string.

x <- "asdf+,jkl?"

gsub("?", " ", x)


Error message:

Error in
gsub("?", " ", x) :
  invalid regular expression '?'
In addition: Warning message:
In gsub("?", " ", x) :
  regcomp error:  'Invalid preceding regular expression'

Your expertise in resolving this issue would be appreciated.

(a) That's funny.  I don't get an error message when I try your example.
I get

[1] " a s d f + , j k l ? "

Of course that's not what you want, though.

(b) You need to escape the question mark:

 > gsub("\\?", " ", x)

yields

[1] "asdf+,jkl "

which I think *is* what you want.

        cheers,

                Rolf Turner



######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to