evaluating a character string as a variable name in an ExpressionSet object
2
0
Entering edit mode
@kavitha-venkatesan-3399
Last seen 9.7 years ago
United States
I would like to know how to evaluate a character string as a variable name in R. Specifically, I need to "compute" the variable name in the phenoData slot of an ExpressionSet object. > varLabels(sample.ExpressionSet) [1] "sex" "type" "score" Now I need to retrieve the factors sample.ExpressionSet$sex, sample.ExpressionSet$type and sample.ExpressionSet$score in turn. Furthermore, I need to be able to generalize my code so that I can retrieve this factor for any phenodata variable in any given ExpressionSet object. Clearly I cannot do something like for (i in c(1:length(varLabels(sample.ExpressionSet))) { class_label <- varLabels(sample.ExpresionSet)[i] class_label_factor <- sample.ExpressionSet$class_label } Here class_label is interpreted as a character string by R, but I need for it to be evaluated as a variable name. Seems straightforward, but I couldn't figure it out...How can I do this? Thanks in advance for any help! Kavitha [[alternative HTML version deleted]]
• 1.1k views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 3 months ago
United States
On Thu, Apr 16, 2009 at 5:58 PM, Kavitha Venkatesan < kavitha.venkatesan@gmail.com> wrote: > I would like to know how to evaluate a character string as a variable name > in R. Specifically, I need to "compute" the variable name in the phenoData > slot of an ExpressionSet object. > > > varLabels(sample.ExpressionSet) > [1] "sex" "type" "score" > > Now I need to retrieve the factors sample.ExpressionSet$sex, > sample.ExpressionSet$type and sample.ExpressionSet$score in turn. > Furthermore, I need to be able to generalize my code so that I can retrieve > this factor for any phenodata variable in any given ExpressionSet object. > > Clearly I cannot do something like > > for (i in c(1:length(varLabels(sample.ExpressionSet))) > { > class_label <- varLabels(sample.ExpresionSet)[i] > class_label_factor <- sample.ExpressionSet$class_label > } > > Here class_label is interpreted as a character string by R, but I need for > it to be evaluated as a variable name. Seems straightforward, but I > couldn't > figure it out...How can I do this? Thanks in advance for any help! > If i is your class label: pData(sample.ExpressionSet)[,i] does that do what you need? Sean [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
@saroj-mohapatra-1446
Last seen 10.2 years ago
Hi Kavitha: Are you looking for something like this: > ls() character(0) > # I have a string called "reallyfunnyvariable" > mystr = "reallyfunnyvariable" # I want to convert this to a variable with the same name; I want it to be a list eval(parse(text=paste(mystr,"=list()",sep=""))) # Now I have the variable > ls() [1] "mystr" "reallyfunnyvariable" # it is a list > reallyfunnyvariable list() You have to be careful though while turning strings into variable, especially in the "batch" mode - what if the string is something like "plot"? You might want to add a clause for first checking if the variable exists, before assigning the variable name. Best, Saroj ----- Original Message ----- From: "Kavitha Venkatesan" <kavitha.venkatesan@gmail.com> To: bioconductor at stat.math.ethz.ch Sent: Thursday, April 16, 2009 5:58:44 PM GMT -05:00 US/Canada Eastern Subject: [BioC] evaluating a character string as a variable name in an ExpressionSet object I would like to know how to evaluate a character string as a variable name in R. Specifically, I need to "compute" the variable name in the phenoData slot of an ExpressionSet object. > varLabels(sample.ExpressionSet) [1] "sex" "type" "score" Now I need to retrieve the factors sample.ExpressionSet$sex, sample.ExpressionSet$type and sample.ExpressionSet$score in turn. Furthermore, I need to be able to generalize my code so that I can retrieve this factor for any phenodata variable in any given ExpressionSet object. Clearly I cannot do something like for (i in c(1:length(varLabels(sample.ExpressionSet))) { class_label <- varLabels(sample.ExpresionSet)[i] class_label_factor <- sample.ExpressionSet$class_label } Here class_label is interpreted as a character string by R, but I need for it to be evaluated as a variable name. Seems straightforward, but I couldn't figure it out...How can I do this? Thanks in advance for any help! Kavitha [[alternative HTML version deleted]] _______________________________________________ Bioconductor mailing list Bioconductor at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Computational Biology VBI @ Virginia Tech
ADD COMMENT

Login before adding your answer.

Traffic: 847 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6