[R] find and replace characters in a string

Rui Barradas ruipbarradas at sapo.pt
Wed Mar 27 17:17:25 CET 2013


Hello,

The period is a metacharacter so you have to escape it.
The period is escaped with a '\'. In it's turn, '\' is a metacharacter 
so it needs to be escaped. Hence the double'\\'.

x <- "LOI ."
gsub("\\.", "(%)", x)


Hope this helps,

Rui Barradas

Em 27-03-2013 16:09, Shane Carey escreveu:
> Hi,
>
> I have a string of text as follows "LOI ."
>
> How do I replace the dot with "(%)"
>
> gsub(".","(%)",LOI .)
>
> gives
>
> "(%)(%)(%)(%)(%)"
>
> Thanks
>



More information about the R-help mailing list