[BioC] R question on symbolic variables
Joern Toedling
Joern.Toedling at curie.fr
Thu Jan 14 10:41:48 CET 2010
Hello,
strictly speaking, this is not a Bioconductor-related question, and most basic
R books that describe the "list" class will probably contain the answer, i.e.
will describe how the "$" operator works for lists.
If you want to use a variable containing the name, use the square brackets:
> a[[b]]
In addition, for creating the list the correct syntax would be:
a <- list("hello"=c(1,2,3), "goodbye"=c(1,2,3)) # '=' instead of '<-'
And for loops over lists, you may want to have a look at the functions
'lapply' and 'sapply'.
Regards,
Joern
On Thu, 14 Jan 2010 09:54:14 +0100, Chris Fenton wrote
> Is this a limitation in the R language or am I missing something
> fundamental (like an operator)
>
> > a <- list("hello"<-c(1,2,3), "goodbye"<-c(1,2,3))
> > a$hello
> [1] 1 2 3
>
> > b <- "hello"
> > a$b
> NULL
>
> So how could we do the following for example.
>
> > info <- names(a)
> > for (i in 1:length(info)){cat(a$info[i]);}
>
> Chris
More information about the Bioconductor
mailing list