SH.Chou
Cc: r-help@r-project.org
Subject: Re: [R] select one function from two of them in another function
Is this what you want -- this returns a function that you can then call:
test1 <- function() 1
test2 <- function() 2
> test3 <- function(func='test1'){ # return the
Is this what you want -- this returns a function that you can then call:
> test1 <- function() 1
> test2 <- function() 2
> test3 <- function(func='test1'){ # return the function to call
+ if (func == 'test1') return(test1)
+ return(test2)
+ }
>
> # test it
> test3()() # default -- notice
Try this:
test1 <- function()cat("Call: Test 1", "\n")
test2 <- function()cat("Call: Test 2", "\n")
test3 <- function(FUN)
match.fun(FUN)
test3("test1")
On Thu, Aug 27, 2009 at 5:39 PM, SH.Chou wrote:
> Hi all, I have two functions called test1() and test2(). Now how do I
> selec
Hi all, I have two functions called test1() and test2(). Now how do I
select one of them in test3()??
Say
test3<-function(func="test1"){
if (func=="test1"){
now.func<-test1()
}
else now.func<-test2()
}
I know this function I wrote does not right. Do an
Hi all, I have two functions called test1() and test2(). Now how do I
select one of them in test3()??
Say
test3<-function(func="test1"){
if (func=="test1"){
now.func<-test1()
}
else now.func<-test2()
}
I know this function I wrote does not right. Do an
5 matches
Mail list logo