[R] Regexpr with "."

John Zhang jzhang at jimmy.harvard.edu
Wed Aug 13 17:01:51 CEST 2003


Try

regexpr("\\.", "Female.Alabama") and gsub("\\.", ",", "Female.Alabama")


>X-Sybari-Trust: 9293cd92 d90ef28b 235e1558 0000093d
>From: "Thompson, Trevor" <tkt2 at cdc.gov>
>To: r-help at stat.math.ethz.ch
>Date: Wed, 13 Aug 2003 10:46:45 -0400
>MIME-Version: 1.0
>X-Virus-Scanned: by amavisd-milter (http://amavis.org/)
>X-Virus-Scanned: by amavisd-milter (http://amavis.org/)
>X-Spam-Status: No, hits=0.6 required=5.0 tests=HTML_30_40 version=2.54
>X-Spam-Level: 
>X-Spam-Checker-Version: SpamAssassin 2.54 (1.174.2.17-2003-05-11-exp)
>Content-Disposition: inline
>Content-Transfer-Encoding: 7bit
>Subject: [R] Regexpr with "."
>X-BeenThere: r-help at stat.math.ethz.ch
>X-Mailman-Version: 2.1.2
>List-Id: Main R Mailing List: Primary help  <r-help.stat.math.ethz.ch>
>List-Help: <mailto:r-help-request at stat.math.ethz.ch?subject=help>
>List-Post: <mailto:r-help at stat.math.ethz.ch>
>List-Subscribe: <https://www.stat.math.ethz.ch/mailman/listinfo/r-help>, 
<mailto:r-help-request at stat.math.ethz.ch?subject=subscribe>
>List-Archive: <https://www.stat.math.ethz.ch/pipermail/r-help>
>List-Unsubscribe: <https://www.stat.math.ethz.ch/mailman/listinfo/r-help>, 
<mailto:r-help-request at stat.math.ethz.ch?subject=unsubscribe>
>
>I'm trying to use the regexpr function to locate the decimal in a character
>string.  Regardless of the position of the decimal, the function returns 1.
>For example,
>
>> regexpr(".", "Female.Alabama")
>[1] 1
>attr(,"match.length")
>[1] 1
>
>In trying to figure out what was going on here, I tried the below command:
>
>> gsub(".", ",", "Female.Alabama")
>[1] ",,,,,,,,,,,,,,"
>
>It looks like R is treating every character in the string as if it were
>decimal.  I didn't see anything in the help file about "." being some kind
>of special character.  Any idea why R is treating a decimal this way in
>these functions?   Any suggestions how to get around this?
>
>Thanks for any suggestions.
>
>-Trevor
> 
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Jianhua Zhang
Department of Biostatistics
Dana-Farber Cancer Institute
44 Binney Street
Boston, MA 02115-6084




More information about the R-help mailing list