Hi, I want to construct a list as Lst <- list(name_1=object_1, ..., name_m=object_m) If name_1 is a variable with value "NAME1", how can I ask R to use "NAME1" instead of 'name_1' as the name of the list element? Thanks! Yupu [[alternative HTML version deleted]]
Try this: as.list(c(object_1, object_2)) On Tue, Sep 22, 2009 at 3:23 PM, YUPU LIANG <liang at cbio.mskcc.org> wrote:> Hi, > > I want to construct a list as > > Lst <- list(name_1=object_1, ..., name_m=object_m) > > If name_1 is a variable with value "NAME1", how can I ask R to use > "NAME1" instead of 'name_1' as the name of the list element? > > Thanks! > Yupu > ? ? ? ?[[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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On 9/22/2009 2:23 PM, YUPU LIANG wrote:> Hi, > > I want to construct a list as > > Lst <- list(name_1=object_1, ..., name_m=object_m) > > If name_1 is a variable with value "NAME1", how can I ask R to use > "NAME1" instead of 'name_1' as the name of the list element?Lst <- list(object_1, ..., object_m) names(Lst) <- c(name_1, ..., name_m) Duncan Murdoch> > Thanks! > Yupu > [[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.
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of YUPU LIANG > Sent: Tuesday, September 22, 2009 11:24 AM > To: r-help at r-project.org > Subject: [R] how to force R to evaluate variable? > > Hi, > > I want to construct a list as > > Lst <- list(name_1=object_1, ..., name_m=object_m) > > If name_1 is a variable with value "NAME1", how can I ask R to use > "NAME1" instead of 'name_1' as the name of the list element?One way is to add the elements one by one using [[<-. E.g., Lst <- list() Lst[[name_1]] <- object_1 Lst[[name_2]] <- object_2 ... You can also do Lst <- list(object_1, object_2, ...) names(Lst) <- c(name_1, name_2, ...) Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com> Thanks! > Yupu > [[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. >