Amir Liu
2009-Dec-02 01:46 UTC
[R] Passing additional argument to be numerically integrated function
Hi, I try to use the numerical integration functionality of R to integrate a univariate (1D) function. Below I am integrating function const1 which works nicely as expected. But for some reasons I need to pass to my function that I want to integrate an additional parameter. If it were object-oriented I just would invoke some setter methods onto a object providing functionality described in function constX and then pass this object on. And according to the help page the function can have more than one argument, just the first needs to be the argument vector for the integration function: - f: an R function taking a numeric first argument and returning a numeric vector of the same length.? Returning a non-finite element will generate an error. But let us say I have an additional argument called nb that I want to pass as well. How would I pass this second argument (and possibly more additional arguments) to make case 2 work, i.e. how this is expressed in R syntax? "integ" <- function() { ? # case 1: no argument for function to be integrated ? # integrate box function of height 1 from 0 to 2 ? val <- integrate(const1,0,2) ? print(val) ? # case 2: one ore more argument for function to be integrated ? # integrate box function of height nb from 0 to 2 ? nb <- 5 ? val1 <- integrate(constX,0,2) ? print(val1) } "const1" <- function(x) { ?return(rep(1,length(x))) } "constX" <- function(x,nb) { ?return(rep(nb,length(nb))) } Kind Regards, Amir -- _________________________________________________________________ View your other email accounts from your Hotmail inbox. Add them now.
Dear R users, and Dr. Delagard I got an R-announce message which tells that R-2.10.0 will be released on December 4, 2009. Houever, it seems the R of that version was already released. At leased I made sure that the R of that version was in Cran and Univ. of Tsukuba, and also Univ. of Toronto. And that version is quite odd because each package is in a folder whih is named coffin. I am seriously worrying that Cran site is hacked and someone might have placed a mallicious version. Please do take a look at the version and make sure if it is really a valid version. Sincerely Hiroto -- -------------------------------------- Hiroto Miyoshi hiroto_miyoshi at nexyzbb.ne.jp
On Tue, Dec 1, 2009 at 6:19 PM, Hiroto Miyoshi <hiroto_miyoshi at nexyzbb.ne.jp> wrote:> > Dear R users, and Dr. Delagard > > I got an R-announce message which tells that > R-2.10.0 will be released on December 4, 2009.According to the message I received it was the first patch release, 2.10.1, that was announced not 2.10.0. -Charlie
On 01/12/2009 9:19 PM, Hiroto Miyoshi wrote:> Dear R users, and Dr. Delagard > > I got an R-announce message which tells that > R-2.10.0 will be released on December 4, 2009.Could you post a copy of that message? The message I saw said "This is to announce that we plan to release R version 2.10.1 on Monday, December 14, 2009." which has a couple of differences from what you describe. Duncan Murdoch> > Houever, it seems the R of that version was already > released. At leased I made sure that the R of that version > was in Cran and Univ. of Tsukuba, and also Univ. of Toronto. > > And that version is quite odd because each package is in > a folder whih is named coffin. I am seriously worrying that > Cran site is hacked and someone might have placed a mallicious > version. > > Please do take a look at the version and make sure if it is > really a valid version. > > Sincerely > > Hiroto > >
David Winsemius
2009-Dec-02 14:56 UTC
[R] Passing additional argument to be numerically integrated function
You may have hidden your posting by responding to an unrelated thread. (Avoid that in the future.) You need to be looking at: ?"function" #and associated topics This will drop you into a discussion that may be germane to your task: http://finzi.psych.upenn.edu/Rhelp08/2009-April/194648.html The above link was found with: RSiteSearch("match args") (There is a function named match.arg, whose precise spelling I had forgotten.) -- David On Dec 1, 2009, at 8:46 PM, Amir Liu wrote:> > > Hi, > > I try to use the numerical integration functionality of R to > integrate a univariate (1D) function. Below I am integrating > function const1 which works nicely as expected. But for some reasons > I need to pass to my function that I want to integrate an additional > parameter. If it were object-oriented I just would invoke some > setter methods onto a object providing functionality described in > function constX and then pass this object on. And according to the > help page the function can have more than one argument, just the > first needs to be the argument vector for the integration function: > > - f: an R function taking a numeric first argument and returning a > numeric vector of the same length. Returning a non-finite element > will generate an error. > > But let us say I have an additional argument called nb that I want > to pass as well. How would I pass this second argument (and possibly > more additional arguments) to make case 2 work, i.e. how this is > expressed in R syntax? > > > "integ" <- function() { > > # case 1: no argument for function to be integrated > # integrate box function of height 1 from 0 to 2 > val <- integrate(const1,0,2) > print(val) > > # case 2: one ore more argument for function to be integrated > # integrate box function of height nb from 0 to 2 > nb <- 5 > val1 <- integrate(constX,0,2) > print(val1) > > } > > "const1" <- function(x) { > return(rep(1,length(x))) > } > > "constX" <- function(x,nb) { > return(rep(nb,length(nb))) > } > > > Kind Regards, > > Amir > --David Winsemius, MD Heritage Laboratories West Hartford, CT