[R] stupid regexp question

David Winsemius dwinsemius at comcast.net
Mon Apr 19 17:54:27 CEST 2010


On Apr 19, 2010, at 11:39 AM, servet ahmet çizmeli wrote:

> Hello,
>
> I have a stupid regexp question. I have a large data frame of  
> strings. I would
> like to convert all occurences of :
>
> "W.m^{-2}"
>
> to
>
> "W/m2"
>
> I make the following test :
>
> gsub(glob2rx("W.m^{-2}"), "W/m2", "W.m^{-2}")

Two problems I see. There is no reason I can see to wrap the pattern  
in glob2rx, and you need to double-back-slash the "specials" when they  
appear in the pattern:

 > gsub("W.m\\^\\{-2\\}", "W/m2", "W.m^{-2}")
[1] "W/m2"

Seems successful on that limited test.
>
--

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list