[R] grep, gsub and metacharacters

Judith Flores juryef at yahoo.com
Fri Aug 22 18:57:10 CEST 2008


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



More information about the R-help mailing list