[R] create a list fails

David Winsemius dwinsemius at comcast.net
Wed Oct 20 17:19:53 CEST 2010


I suspect that Dr. Jim is conflating the behavior of R w.r.t.  
arguments in a function call (where assignment to one argument can be  
"seen" by another argument)  with the behavior of naming items in a  
list expression.

-- 
David.

On Oct 20, 2010, at 11:01 AM, jim holtman wrote:

> I do not see that it has been "created" yet.  You my have defined it
> earlier in the 'list' expression, but as an object it is not available
> yet.  You might have to do something like uwing 'within'
>
>> x <- list()
>> x <- within(x, {
> + a = 1:10
> + b = 11:20
> + c = a + b
> + d = a * b})
>> x
> $d
> [1]  11  24  39  56  75  96 119 144 171 200
>
> $c
> [1] 12 14 16 18 20 22 24 26 28 30
>
> $b
> [1] 11 12 13 14 15 16 17 18 19 20
>
> $a
> [1]  1  2  3  4  5  6  7  8  9 10
>
>>
> On Wed, Oct 20, 2010 at 10:42 AM, 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

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list