[R] Regexpr with "."
Uwe Ligges
ligges at statistik.uni-dortmund.de
Wed Aug 13 17:03:26 CEST 2003
Thompson, Trevor wrote:
> 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
Think about the meaning of "." in regular expression (it needs to be
escaped as being a special character!):
gsub("\\.", ",", "Female.Alabama")
or
regexpr("\\.", "Female.Alabama")
Uwe Ligges
More information about the R-help
mailing list