An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130228/c8a85167/attachment.pl>
Dealing with parentheses within variable names
5 messages · Jesus Munoz Serrano, Bert Gunter, arun +1 more
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))
instead.
-- 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 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Oops -- forgot that you have to double the backslashes:
So use:
sub("\\(\\)","", names(dataFrame))
-- Bert
On Thu, Feb 28, 2013 at 1:20 PM, Bert Gunter <bgunter at gene.com> wrote:
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))
instead.
-- 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 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Hi,
You could also try:
gsub("[()]","",names(dataFrame))
set.seed(15)
?datF<- data.frame(sample(1:10,15,replace=TRUE))
?names(datF)<-?? "fBodyGyroskewness()Z"
gsub("[()]","",names(datF))
#[1] "fBodyGyroskewnessZ"
sub("\\(\\)","",names(datF))
#[1] "fBodyGyroskewnessZ"
A.K.
----- Original Message -----
From: Bert Gunter <gunter.berton at gene.com>
To: Jesus Munoz Serrano <jesusmunozserrano at gmail.com>
Cc: r-help at r-project.org
Sent: Thursday, February 28, 2013 4:25 PM
Subject: Re: [R] Dealing with parentheses within variable names
Oops -- forgot that you have to double the backslashes:
So use:
sub("\\(\\)","", names(dataFrame))
-- Bert
On Thu, Feb 28, 2013 at 1:20 PM, Bert Gunter <bgunter at gene.com> wrote:
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))
instead.
-- 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 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ 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.
On 28/02/2013 11:08 AM, Jesus Munoz Serrano 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.
R shouldn't have trouble with names like that, but a lot of packages will (e.g. the ones that construct strings and call parse() on them). If you find functions in base R that object to those names, I think we'd like to fix them. If the functions are in contributed packages, your mileage may vary. Duncan Murdoch