[R] Interpreting a string as a variable in a column header

Greg Snow Greg.Snow at intermountainmail.org
Thu Jul 12 20:51:22 CEST 2007


Use xx[[gene]] instead of xx$gene (the $ is a shorthand for [[ with some
extra magic to be more convenient, the magic is getting in your way, so
go back to the [[ syntax (make sure you double the braces)).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of rosa clements
> Sent: Thursday, July 12, 2007 11:39 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Interpreting a string as a variable in a column header
> 
> This must be a very simple question, but I can't find any 
> information on it elsewhere, sorry. When extracting 
> information from a list using column headers, how do I get R 
> to interpret something as a variable rather than a string? 
> For example:
> 
> xx$"YAL002"
> 
> works, but this doesn't:
> 
> gene <- "YAL002"
> xx$gene
> 
> neither do
> 
> xx$parse(gene)
> xx$eval(gene)
> xx$eval(parse(gene))
> 
> or a variety of other constructions I have tried.
> 
> Background: I have a table of information about yeast genes, 
> and I also have a list of yeast genes and their GO terms (xx) 
> from the YEAST package that I downloaded. I want to go 
> through all the genes in my table and look up their GO terms 
> in the list from the YEAST package.
> They might not contain exactly the same genes (ideally they 
> should, but I'd be surprised if they do) and I don't think 
> they're in the same order, so I do want to use the column 
> names, but there are a lot of them so I'm not typing them all 
> out individually. It might be possible to turn the GO data 
> into something other than a list, but the help page 
> recommends using xx <- as.list(YEASTGO) and doesn't make any 
> other suggestions, so I should probably do as I'm told.
> 
> Thanks for any help or suggestions of where to look,
> 
> Rosa
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list