Oh, I'm jetlagged. ^ is a control character for 'start of string'. In the context of a character set it means negation: [^a-z].
Ciao, Tsjerk On Mon, Jan 21, 2013 at 4:33 PM, Tsjerk Wassenaar <tsje...@gmail.com> wrote: > Hi Mark Na, > > Try: > > grepl("latitude\\^2",temp) > > ^ is a control character for negation, so you have to escape it. > > Cheers, > > Tsjerk > > > On Mon, Jan 21, 2013 at 4:26 PM, <mtb...@gmail.com> wrote: > >> Hello R-helpers, >> >> I am trying to search for string that includes the caret symbol, using the >> following code: >> >> grepl("latitude^2",temp) >> >> >> And R doesn't like that. It gives me: >> >> > temp<-c("latitude^2","latitude and latitude^2","longitude^2","longitude >> and longitude^2") >> > temp >> [1] "latitude^2" "latitude and latitude^2" "longitude^2" >> "longitude and longitude^2" >> > grepl("latitude^2",temp) >> [1] FALSE FALSE FALSE FALSE >> >> >> I think this must a regex problem, but I can't find out to specify the >> caret using regex. >> >> I would appreciate any help you could provide. >> >> Many thanks, >> >> Mark Na >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> 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. >> > > > > -- > Tsjerk A. Wassenaar, Ph.D. > > post-doctoral researcher > Biocomputing Group > Department of Biological Sciences > 2500 University Drive NW > Calgary, AB T2N 1N4 > Canada > -- Tsjerk A. Wassenaar, Ph.D. post-doctoral researcher Biocomputing Group Department of Biological Sciences 2500 University Drive NW Calgary, AB T2N 1N4 Canada [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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.