Dear R-users, I would like to assign elements to a list in the following manner: mylist <- list(a = a, b = b, c = c) To do this I tried myexpr <- expression(a = a, b = b, c = c) mylist <- list( eval(myexpr) ) It ends up by overwriting a when b is assigned and b when c is assigned. Additionally the element of the list does not have a name. Could you tell me why this is the case? Thank you very much in advance! Best regards, Nils
I think this is glossing over 9.7 of 'The R Inferno'. You aren't telling us what you really want to achieve. It seems hard for me to believe that the approach you are taking is going to be the easiest route to whatever that is. Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of "The R Inferno" and "A Guide for the Unwilling S User") Skotara wrote:> Dear R-users, > > I would like to assign elements to a list in the following manner: > mylist <- list(a = a, b = b, c = c) > > To do this I tried > myexpr <- expression(a = a, b = b, c = c) > mylist <- list( eval(myexpr) ) > > It ends up by overwriting a when b is assigned and b when c is > assigned. Additionally the element of the list does not have a name. > Could you tell me why this is the case? > Thank you very much in advance! > > Best regards, > Nils > > ______________________________________________ > 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. > >
The purpose of this is not clear but depending on what a and b are you might be able to use a data frame (which is a list):> a <- 1:2; b <- 3:4 > data.frame(a, b)a b 1 1 3 2 2 4 On Mon, Jan 12, 2009 at 9:42 AM, Skotara <nils.skotara at uni-hamburg.de> wrote:> Dear R-users, > > I would like to assign elements to a list in the following manner: > mylist <- list(a = a, b = b, c = c) > > To do this I tried > myexpr <- expression(a = a, b = b, c = c) > mylist <- list( eval(myexpr) ) > > It ends up by overwriting a when b is assigned and b when c is assigned. > Additionally the element of the list does not have a name. > Could you tell me why this is the case? > Thank you very much in advance! > > Best regards, > Nils > > ______________________________________________ > 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. >