Re: [R] Defining functions inside loops

2011-02-15 Thread Eduardo de Oliveira Horta
ilder_1.0 revoIpe_1.0       tools_2.11.1 >>>> [5] XML_3.1-0 >>>> >>>> > On Mon, Nov 15, 2010 at 7:10 PM, William Dunlap >>>> > wrote: >>>> >> You could make f[[i]] be function(t)t^2+i for i in 1:10 >>>> >> wit

Re: [R] Defining functions inside loops

2011-02-15 Thread jim holtman
<- lapply(1:10, function(i)local({ force(i) ; function(x)x^2+i})) >>> >> After that we get the correct results >>> >>    > f[[7]](100:103) >>> >>    [1] 10007 10208 10411 10616 >>> >> but looking at the function doesn't

Re: [R] Defining functions inside loops

2011-02-15 Thread Dr. Matthias Kohl
t.org [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de Oliveira Horta Sent: Monday, November 15, 2010 12:50 PM To: r-help@r-project.org Subject: [R] Defining functions inside loops Hello, I was trying to define a set of functions inside a loop, with the loop index working as a parameter for

Re: [R] Defining functions inside loops

2011-02-15 Thread Eduardo de Oliveira Horta
03) >> >>    [1] 10007 10208 10411 10616 >> >> but looking at the function doesn't immdiately tell you >> >> what 'i' is in the function >> >>    > f[[7]] >> >>    function (x) >> >>    x^2 + i >&g

Re: [R] Defining functions inside loops

2011-02-15 Thread jim holtman
can find it in f[[7]]'s environment >>>    > get("i", envir=environment(f[[7]])) >>>    [1] 7 >>> >>> The call to force() in the call to local() is not >>> necessary in this case, although it can help in >>> other situations. >>>

Re: [R] Defining functions inside loops

2011-02-15 Thread Dennis Murphy
f[[7]])) > >>[1] 7 > >> > >> The call to force() in the call to local() is not > >> necessary in this case, although it can help in > >> other situations. > >> > >> Bill Dunlap > >> Spotfire, TIBCO Software > >> wd

Re: [R] Defining functions inside loops

2011-02-14 Thread Eduardo de Oliveira Horta
lap >> Spotfire, TIBCO Software >> wdunlap tibco.com >> >>> -----Original Message----- >>> From: r-help-boun...@r-project.org >>> [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de >>> Oliveira Horta >>> Sent: Monday, November

Re: [R] Defining functions inside loops

2010-11-15 Thread Duncan Murdoch
rg] On Behalf Of Eduardo de Oliveira Horta Sent: Monday, November 15, 2010 12:50 PM To: r-help@r-project.org Subject: [R] Defining functions inside loops Hello, I was trying to define a set of functions inside a loop, with the loop index working as a parameter for each function. Below I post a simpler e

Re: [R] Defining functions inside loops

2010-11-15 Thread Eduardo de Oliveira Horta
t; wdunlap tibco.com > > > -Original Message- > > From: r-help-boun...@r-project.org > > [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de > > Oliveira Horta > > Sent: Monday, November 15, 2010 12:50 PM > > To: r-help@r-project.org &g

Re: [R] Defining functions inside loops

2010-11-15 Thread William Dunlap
r situations. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de > Oliveira Horta > Sent: Monday, November 15, 2010 12:50 PM > To: r-help@

Re: [R] Defining functions inside loops

2010-11-15 Thread Greg Snow
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Eduardo de Oliveira Horta > Sent: Monday, November 15, 2010 1:50 PM > To: r-help@r-project.org > Subject: [R] Defining functions inside loops > > Hel

[R] Defining functions inside loops

2010-11-15 Thread Eduardo de Oliveira Horta
Hello, I was trying to define a set of functions inside a loop, with the loop index working as a parameter for each function. Below I post a simpler example, as to illustrate what I was intending: f<-list() for (i in 1:10){ f[[i]]<-function(t){ f[[i]]<-t^2+i } } rm(i) With that, I was ex