[R] Replacing Period in String

From: Sparks, John James <jspark4_at_uic.edu>
Date: Sun, 20 Mar 2011 23:49:05 -0500

Dear R Users,

I am working with gsub for the first time. I am trying to remove some characters from a string. I have hit the problem where the period is the shorthand for 'everything' in the R language when what I want to remove is the actual periods. In the example below, I simply want to remove the periods as I have removed the comma, but instead the complete string is wiped out. I would appreciate it if someone could let me know how I communicate that I want to remove the period verbatim to R.

Many thanks.
--John Sparks

> txt="This is a test. However, it is only a test."
> txt2<-gsub(",","",txt)
> txt2

[1] "This is a test. However it is only a test."
> txt3<-gsub(".","",txt)
> txt3

[1] ""

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. Received on Mon 21 Mar 2011 - 04:53:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Mar 2011 - 09:50:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive