[R] Replace a dot in a string (".") with a space (" ")

Bert Gunter bgunter.4567 at gmail.com
Sat Nov 19 02:35:22 CET 2016


Well of course. See ?regexp where it says:

"The period . matches any single character. "

(Always a good idea to read man pages, although this *is* a complex one)

Setting the fixed argument to TRUE  is one way to get what you want
(there are others).

> sub(".", " ", "c.t",fixed=TRUE)
[1] "c t"

Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Nov 18, 2016 at 4:13 PM, John <miaojpm at gmail.com> wrote:
> Hi,
>
>    Is there any function that replaces a dot with a space? I expect "c t"
> from the output of the second call of function sub, but it did not do so.
>
>> sub("a", "b", "cat")
> [1] "cbt"
>> sub(".", " ", "c.t")
> [1] " .t"
>
> Thanks!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list