[R] Dealing with parentheses within variable names

Bert Gunter gunter.berton at gene.com
Thu Feb 28 22:20:27 CET 2013

Please read ?regex, where it says:

" Any metacharacter with special meaning may be quoted by preceding it
with a backslash. The metacharacters in EREs are . \ | ( ) [ { ^ $ * +
?, but note that whether these have a special meaning depends on the
context. "

So use:
sub("\(\)","", names(dataFrame))


-- Bert

On Thu, Feb 28, 2013 at 8:08 AM, Jesus Munoz Serrano
<jesusmunozserrano at gmail.com> wrote:
> Dear all
> I'm having some problems with a data set that has parenthesis within the variable names. A example of this kind of variable names is the following:
>                                 fBodyGyroskewness()Z
> The case is that R is having a lot of troubles to identify the variable (probably it does understand it like a function). I've tried (among other things) to remove the parenthesis from the name using the following command:
>                                 names(dataFrame) <- sub("()","", names(dataFrame))
> but It didn't work.  Sorry if it's a silly issue but I would really appreciate if anybody could help me. Thank you very much.
>         [[alternative HTML version deleted]]
> ______________________________________________
> 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.


Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374

More information about the R-help mailing list