[R] create a list fails

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed Oct 20 17:31:46 CEST 2010


Your first example is all one statement. Within that statement you are defining elements of a list. Unfortunately you are defining some of those elements in terms of others, but they don't exist until the statement has completed. If you break the statement up into an initial list formation statement followed by additional statements that successively append to the list, you will be able to refer to "previously-defined" list elements on the right side of assignments.

"Maas James Dr (MED)" <J.Maas at uea.ac.uk> wrote:

>I can not understand why this fails
>
>>
>> faicoutput2 <- list(stuff21 = as.numeric(faicout$coefficients[2]),
>+                      stuff31=as.numeric(faicout$coefficients[3]),
>+                      stuff41=as.numeric(faicout$coefficients[4]),
>+                      stuff32=(stuff21-stuff31),
>+                      stuff42=(stuff21-stuff41),
>+                      stuff43=(stuff32-stuff42)
>+                      )
>Error: object 'stuff21' not found
>>
>Why does it have to be found, exist previously ... it is being created?
>
>
>But this works fine ....
>
>data <- list(Ntrials =numtritot, Ncomparisons=2,
>             treat=c(rep(1 ,N.trials[1,2]), rep(2,N.trials[1,3])),
>             total.patientnums.trt1=dat2[ ,2],
>             total.patientnums.trt23=dat2[ ,2],
>             num.countstrt1=dat2[ ,5],
>             num.countstrt23=dat2[ ,6] )
>
>
> .... ????
>
>
>
>
>
>===============================
>Dr. Jim Maas
>University of East Anglia
>
>
>	[[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.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list