[R] function to create multiple lists
    David Winsemius 
    dwinsemius at comcast.net
       
    Sat Jan 30 00:35:18 CET 2010
    
    
  
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)
> 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