Re: [R] grep, gsub and metacharacters

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Fri, 22 Aug 2008 11:22:54 -0600

Try this:

> myvector<-c("ajkhfkiuwe","Variable(kg/min)")
> gsub( "\\(kg/min\\)", "va", myvector )

Does that come close to what you want? If not, maybe an example of what you want the result to look like,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111




> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Judith Flores
> Sent: Friday, August 22, 2008 10:57 AM
> To: RHelp
> Subject: [R] grep, gsub and metacharacters
>
> Hello,
>
> I have an expression that I want to substitute for something else.
>
> myvector<-c("ajkhfkiuwe","Variable(kg/min)")
>
> if I use the following code to extract "variable(kg/min)" and
> substitute it for "va"
>
> gsub(myvector[grep("var", myvector, ignore=T)], "va", myvector)
>
> grep identifies the element of the vector that matches my
> query, but it won't substitute the value. I have been reading
> the help pages for regular expression, but still can't figure
> out the syntax to read parenthesis and forward slashes, which
> are considered metacharacters.
>
>
> As usual, thank you for your help,
>
> Judith
>
> ______________________________________________
> R-help_at_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.
>
______________________________________________ R-help_at_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.
Received on Fri 22 Aug 2008 - 17:25:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 22 Aug 2008 - 18:33:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive