[R] delete "-character from strings in matrix

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Mon Jun 13 01:38:39 CEST 2005


You will need to escape special characters. Here is an example :

 my.string <- "Here is a quote \" in a string"
 my.string
  [1] "Here is a quote \" in a string"

 gsub("\"", "", my.string)
  [1] "Here is a quote  in a string"
 
See help(regexp) for more details.

Regards, Adai



On Sun, 2005-06-12 at 14:10 +0200, Werner Wernersen wrote:
> Thanks for the reply, Andy!
> 
> My problem was that I could not get rid of a double
> quote character within the 
> string. I don't know what I have done before, but now
> it works...?!?!
> Sorry for bothering you.
> 
> Best,
>    Werner
> 
> 
> Liaw, Andy wrote:
> > Please define "does not work".  Here's what I get:
> > 
> > 
> >>m <- matrix(paste(letters[1:4], "does not work."),
> 2, 2)
> >>m
> > 
> >      [,1]               [,2]              
> > [1,] "a does not work." "c does not work."
> > [2,] "b does not work." "d does not work."
> > 
> >>gsub("does not work.", "", m)
> > 
> > [1] "a " "b " "c " "d "
> > 
> >>structure(gsub("does not work.", "", m), dim=dim(m))
> > 
> >      [,1] [,2]
> > [1,] "a " "c "
> > [2,] "b " "d "
> > 
> > R-2.1.0 on WinXPPro.
> > 
> > Andy 
> > 
> > 
> >>From: Werner Wernersen
> >>
> >>Hi!
> >>
> >>I have strings where occasionally some "-chars
> occur.
> >>How can I delete these chars?
> >>
> >>I tried it with gsub but using "" as replace does
> not
> >>work.
> >>
> >>Thanks a lot for any hint!
> >>Regards,
> >>   Werner
> >>
> >>______________________________________________
> >>R-help at stat.math.ethz.ch mailing list
> >>https://stat.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide! 
> >>http://www.R-project.org/posting-guide.html
> >>
> >>
> >>
> > 
> > 
> > 
> > 
> >
> ------------------------------------------------------------------------------
> > Notice:  This e-mail message, together with any
> attachments, contains information of Merck & Co., Inc.
> (One Merck Drive, Whitehouse Station, New Jersey, USA
> 08889), and/or its affiliates (which may be known
> outside the United States as Merck Frosst, Merck Sharp
> & Dohme or MSD and in Japan, as Banyu) that may be
> confidential, proprietary copyrighted and/or legally
> privileged. It is intended solely for the use of the
> individual or entity named on this message.  If you
> are not the intended recipient, and have received this
> message in error, please notify us immediately by
> reply e-mail and then delete it from your system.
> >
> ------------------------------------------------------------------------------
> > 
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list