Re: [R] generated list element names

2012-11-19 Thread David Winsemius
On Nov 19, 2012, at 10:46 AM, William Dunlap wrote: If you have a list and want to add a new (or replace a) named component use myList[[compName]] <- compValue as in myList <- list() compName <- "Incr" compValue <- function(x) x + 1 myList[[compName]] <- compValue If you want to make

Re: [R] generated list element names

2012-11-19 Thread jim holtman
I missed the last snipet; just saw the first. So you have your solution. If you want a function, try: > f.newList <- function(x,name){.x <- list(x);names(.x) <- name;.x} > f.newList(10, paste('f', 'oo', sep = '')) $foo [1] 10 On Mon, Nov 19, 2012 at 1:32 PM, Sam Steingold wrote: >> * jim holt

Re: [R] generated list element names

2012-11-19 Thread William Dunlap
If you have a list and want to add a new (or replace a) named component use myList[[compName]] <- compValue as in myList <- list() compName <- "Incr" compValue <- function(x) x + 1 myList[[compName]] <- compValue If you want to make a new list-with-names from scratch try structur

Re: [R] generated list element names

2012-11-19 Thread Sam Steingold
> * jim holtman [2012-11-19 13:14:05 -0500]: > > How about this (if you don't like writing two lines, encapsulate it in > a function): > >> x <- list(10) >> names(x) <- paste('f', 'oo', sep = '') >> str(x) > List of 1 > $ foo: num 10 >> I am sorry, how is this different from my second snippet (e

Re: [R] generated list element names

2012-11-19 Thread jim holtman
How about this (if you don't like writing two lines, encapsulate it in a function): > x <- list(10) > names(x) <- paste('f', 'oo', sep = '') > str(x) List of 1 $ foo: num 10 > On Mon, Nov 19, 2012 at 1:07 PM, Sam Steingold wrote: > How can I create lists with element names created on the fly?