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:
>>
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
> > p
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
s
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
Hi Duncan -
Thanks for the reply. Yeah, I understand what I'm doing is a bit weird, but
I'm actually calling a few functions w/in the for-loop that need the value
of the "i" var, and because I was a bit confused by the concept of
environments, I was hoping to avoid having to pass it in as an arg
On 17/04/2008 5:37 PM, Peter Waltman wrote:
> 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
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" )
7 matches
Mail list logo