Hi There
I'm not very sure how to replace the stars in a character vector
For example:
a character vector (n rows by 1 col)
[1] "-27 -21 -25 -28**** ***** -29"
[2] "-27 ******** -28**** ***** -29"
.
.
.
.
.
.
[n] "-1***********************************"
I wish to replace all the *s with a blank, result as per below
[1] "-27 -21 -25 -28 -29"
[2] "-27 -28 -29"
.
.
.
.
.
.
[n] "-1 "
I have tried to use gsub( )
like: gsub("*", "", x)
but doesn't seem to be working...please advise
Thank you
Ruby
[[alternative HTML version deleted]]
gsub("\\*", " ",x)
should do. Please read about regular expression as used by gsub().
Uwe Ligges
On 20.04.2011 12:00, Ruby Chu wrote:> Hi There
>
> I'm not very sure how to replace the stars in a character vector
>
> For example:
>
> a character vector (n rows by 1 col)
>
> [1] "-27 -21 -25 -28**** ***** -29"
> [2] "-27 ******** -28**** ***** -29"
> .
> .
> .
> .
> .
> .
> [n] "-1***********************************"
>
> I wish to replace all the *s with a blank, result as per below
>
> [1] "-27 -21 -25 -28 -29"
> [2] "-27 -28 -29"
> .
> .
> .
> .
> .
> .
> [n] "-1 "
>
> I have tried to use gsub( )
> like: gsub("*", "", x)
> but doesn't seem to be working...please advise
>
> Thank you
>
> Ruby
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
On Apr 20, 2011, at 6:00 AM, Ruby Chu wrote:> Hi There > > I'm not very sure how to replace the stars in a character vector > > For example: > > a character vector (n rows by 1 col) > > [1] "-27 -21 -25 -28**** ***** -29" > [2] "-27 ******** -28**** ***** -29" > . > . > . > . > . > . > [n] "-1***********************************" > > I wish to replace all the *s with a blank, result as per below > > [1] "-27 -21 -25 -28 -29" > [2] "-27 -28 -29" > . > . > . > . > . > . > [n] "-1 " > > I have tried to use gsub( ) > like: gsub("*", "", x)"*" is an operator in regex, so you need to double escape it in the pattern argument (but may not need to escape it in the replace argument. > gsub("\\*", "", "test8888****8888****9999") [1] "test888888889999" > gsub("\\.", "*", "test8888...8888...9999") [1] "test8888***8888***9999"> but doesn't seem to be working...please advise > > Thank you > > Ruby > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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 West Hartford, CT
Seemingly Similar Threads
- Function to eliminate blank space within strings?
- Star rating system - IE display problems
- Star Wars Empire at War opens blank text box instead of game
- Problem with plotting size/location on variation of star/segment plot
- Problems with labels and scaling in star diagrams