[BioC] evaluating a character string as a variable name in an ExpressionSet object

Martin Morgan mtmorgan at fhcrc.org
Fri Apr 17 05:41:08 CEST 2009


Hi Kavitha -- 

Kavitha Venkatesan <kavitha.venkatesan at gmail.com> writes:

> 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.

Use [[ rather than $.

> data(sample.ExpressionSet)
> sample.ExpressionSet[["sex"]]
 [1] Female Male   Male   Male   Female Male   Male   Male   Female Male  
[11] Male   Female Male   Male   Female Female Female Male   Male   Female
[21] Male   Female Male   Male   Female Female
Levels: Female Male

e.g.,

> for (lbl in varLabels(sample.ExpressionSet))
+     print(sample.ExpressionSet[[lbl]])
 [1] Female Male   Male   Male   Female Male   Male   Male   Female Male  
[11] Male   Female Male   Male   Female Female Female Male   Male   Female
[21] Male   Female Male   Male   Female Female
Levels: Female Male
 [1] Control Case    Control Case    Case    Control Case    Case    Case   
[10] Control Case    Control Case    Case    Case    Control Case    Control
[19] Case    Case    Control Control Control Control Case    Case   
Levels: Case Control
 [1] 0.75 0.40 0.73 0.42 0.93 0.22 0.96 0.79 0.37 0.63 0.26 0.36 0.41 0.80 0.10
[16] 0.41 0.16 0.72 0.17 0.74 0.35 0.77 0.27 0.98 0.94 0.32


Martin

> 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

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793



More information about the Bioconductor mailing list