Re: [R] Two functions as parametrs of a function.

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 07 Apr 2011 09:05:19 -0300

Try this:

f2 <- function(n, nsim, fun1, fun2) {

	vp <- replicate(nsim, do.call(fun1$name, c(n, fun1$args)),
				    do.call(fun1$name, c(n, fun1$args)))
	vp

}

f2(2, 100, fun1 = list(name = rbeta, args = list(shape1 = 2, shape2 = 2), fun1 = list(name = rbeta, args = list(shape1 = 2, shape2 = 2))))

On Thu, Apr 7, 2011 at 8:45 AM, Kenneth Roy Cabrera Torres <krcabrer_at_une.net.co> wrote:
> Hi R users:
>
> I'm trying to make a function where two of the parameters are
> functions, but I don't know how to put each set of parameters for
> each function.
>
> What am I missing?
>
> I try this code:
>
> f2<-function(n=2,nsim=100,fun1=rnorm,par1=list(),fun2=rnorm,par2=list()){
>    force(fun1)
>    force(fun2)
>    force(n)
>    p1<-unlist(par1)
>    p2<-unlist(par2)
>    force(p1)
>    force(p2)
>    localfun1 <- function() fun1(n, p1)
>    localfun2 <- function() fun2(n, p2)
>    vp<-replicate(nsim,t.test(localfun1(), localfun2())$p.value)
>    return(vp)
> }
>
> f2(fun1=rbeta,par1=list(shape1=2,shape2=2),fun2=rbeta,par2=list(shape1=1,shape2=2))
>
> Thank you for your help.
>
> Kenneth
>
> ______________________________________________
> R-help_at_r-project.org mailing list
>
https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 07 Apr 2011 - 12:07:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 14:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive