If you define your functions in the loop you can it directly
since then the scoping rules work in your favor:
for(i in 1:4) {
f - function() i*i
print(f())
}
or via lapply:
F - function(i) { f - function() i*i; print(f()) }
lapply(1:4, F)
Often the sort of situation you discuss is really
On 18/04/2008 7:27 AM, Gabor Grothendieck wrote:
If you define your functions in the loop you can it directly
since then the scoping rules work in your favor:
for(i in 1:4) {
f - function() i*i
print(f())
}
f doesn't need to be in the loop, it just needs to be defined in the
same
On Fri, Apr 18, 2008 at 7:49 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
On 18/04/2008 7:27 AM, Gabor Grothendieck wrote:
If you define your functions in the loop you can it directly
since then the scoping rules work in your favor:
for(i in 1:4) {
f - function() i*i
print(f())
}
On 4/18/2008 9:19 AM, Gabor Grothendieck wrote:
On Fri, Apr 18, 2008 at 7:49 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
On 18/04/2008 7:27 AM, Gabor Grothendieck wrote:
If you define your functions in the loop you can it directly
since then the scoping rules work in your favor:
for(i in
Hi -
I'm having a really hard time w/understanding R's get function, and would
appreciate any help with this.
Specifically, I'm using a for loop to call a function. I'd like the
function to have access to the variable being incremented in the for-loop,
i.e.
t.fn - function() return( get( i ) )
5 matches
Mail list logo