[R] Creating a list of functions

2008-06-05 Thread Andreas Posch
I've been trying to create a list of function where function[[i]] should actually return the value of i. trying: func - vector(list,2) i - 1 while (i = 2) { func[[i]] - function() { i } i - i+1 } however only returned the last value of i for each function. Any help how to achieve the solution

Re: [R] Creating a list of functions

2008-06-05 Thread jim holtman
Is this what you want: func - vector(list,2) i - 1 while (i = 2) + { + func[[i]] - local({ + z - i + function(){ z } + }) + i - i+1 + } func[[1]]() [1] 1 func[[2]]() [1] 2 Your solution was using 'i' which picked up the last definition of 'i'. 'local' create a

Re: [R] Creating a list of functions

2008-06-05 Thread Duncan Murdoch
On 6/5/2008 10:50 AM, Andreas Posch wrote: I've been trying to create a list of function where function[[i]] should actually return the value of i. trying: func - vector(list,2) i - 1 while (i = 2) { func[[i]] - function() { i } i - i+1 } however only returned the last value of i for each