[R] function to create multiple lists
David Winsemius
dwinsemius at comcast.net
Sat Jan 30 00:56:21 CET 2010
On Jan 29, 2010, at 6:35 PM, David Winsemius wrote:
>
> On Jan 29, 2010, at 6:16 PM, Cat Morning wrote:
>
>> Hi all,
>> I want to write a function to create multiple lists (over 100
>> lists). For example:
>>
>> for(i in 1:5)
>> pi = c(1:5)
>
> Try:
> p <-list()
> for(i in 1:5)
> p[[i]] = 1:5
>
> You can reference the third elements of the first vector as:
>
> p[[1]][3]
>
>>
>> but when i type:
>> p2
>> i get the error
>> Error: object 'p2' not found
>>
>> I want the lists to be numbered in this fashion, because I want to
>> create another function that goes something like:
>> for(i in 1:5)
>> {if(pi[1]*pi[1] = = 2)
Not sure what you intended here. Did you mean the square of pi[1] ,
which I would have structured as p[[i]][1] , would be tested for
equality with an integer? Ain't going to happen. Read up on the FAQ's
materiall regarding the different uses of "==" and all.equal().
>> print(pi)}
>>
>> any ideas on how to get around this problem would be greatly
>> appreciated.
>>
>> Thanks,
> --
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list