Re: [R] Removing + and ? signs

2009-11-23 Thread Peter Dalgaard

Jorge Ivan Velez wrote:

And if you want to replace both + and ?, here is a suggestion:

x - asdf+,jkl?
gsub([?]|[+], , x)
# [1] asdf,jkl


Once you're into character classes ([]), you might as well go all 
the way:


 gsub([?+], , x)
[1] asdf,jkl



--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
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.


Re: [R] Removing + and ? signs

2009-11-22 Thread jim holtman
'?' is a metacharacter in a regular expression.  You have to escape it:

 x - asdf+,jkl?

 gsub(?,  , x)
Error in gsub(?,  , x) : invalid regular expression '?'
In addition: Warning message:
In gsub(?,  , x) :
  regcomp error:  'Invalid preceding regular expression'
 # escape it
 gsub(\\?,  , x)
[1] asdf+,jkl 


On Sun, Nov 22, 2009 at 6:01 PM, Steven Kang stochastick...@gmail.com 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.

 Thanks.



 Steven

        [[alternative HTML version deleted]]

 __
 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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.


Re: [R] Removing + and ? signs

2009-11-22 Thread Linlin Yan
Try this:
gsub([?],  , x)

On Mon, Nov 23, 2009 at 7:01 AM, Steven Kang stochastick...@gmail.com 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.

 Thanks.



 Steven

        [[alternative HTML version deleted]]

 __
 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.


__
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.


Re: [R] Removing + and ? signs

2009-11-22 Thread Jorge Ivan Velez
Dear Steven,

You were almost there:

 x - asdf+,jkl?
 gsub(\\?, , x)
[1] asdf+,jkl

 gsub(\\+, , x)
[1] asdf,jkl?

Take a look at the Basic Regular Expressions section in ?regex for more
details.

HTH,
Jorge


On Sun, Nov 22, 2009 at 6: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.

 Thanks.



 Steven

[[alternative HTML version deleted]]

 __
 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.


[[alternative HTML version deleted]]

__
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.


Re: [R] Removing + and ? signs

2009-11-22 Thread Rolf Turner


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.


Re: [R] Removing + and ? signs

2009-11-22 Thread Jorge Ivan Velez
And if you want to replace both + and ?, here is a suggestion:

x - asdf+,jkl?
gsub([?]|[+], , x)
# [1] asdf,jkl

HTH,
Jorge


On Sun, Nov 22, 2009 at 6:46 PM, Jorge Ivan Velez  wrote:

 Dear Steven,

 You were almost there:

  x - asdf+,jkl?
  gsub(\\?, , x)
 [1] asdf+,jkl

  gsub(\\+, , x)
 [1] asdf,jkl?

 Take a look at the Basic Regular Expressions section in ?regex for more
 details.

 HTH,
 Jorge


 On Sun, Nov 22, 2009 at 6: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.

 Thanks.



 Steven

[[alternative HTML version deleted]]

 __
 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.




[[alternative HTML version deleted]]

__
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.


Re: [R] Removing + and ? signs

2009-11-22 Thread David Winsemius


On Nov 22, 2009, at 6: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)


Since both ? and + are special regex characters, to do both the  
substitutions at once you need to use double backslashes and an or


 gsub(\\?|\\+,  , x)
[1] asdf ,jkl 

--
David




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.

Thanks.



Steven

[[alternative HTML version deleted]]

__
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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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.