Re: [R] Using if statement on function

2010-06-28 Thread Duncan Murdoch
On 28/06/2010 5:50 AM, Etienne Stockhausen wrote: Hello everybody, I'm trying to use a if-statment on a function. For a better understanding I want to present a small example: FUN=mean # could also be median,sd or any other function if (FUN == mean)

Re: [R] Using if statement on function

2010-06-28 Thread Keith Jewell
You could also consider isTRUE(all.equal(FUN, mean)) > isTRUE(all.equal(mean, mean)) [1] TRUE > isTRUE(all.equal(mean, median)) [1] FALSE HTH Keith J "Patrick Burns" wrote in message news:4c28777f.1040...@pburns.seanet.com... > If I understand the problem properly, > you want something li

Re: [R] Using if statement on function

2010-06-28 Thread Patrick Burns
If I understand the problem properly, you want something like this: function(FUN, ...) { FunName <- deparse(substitute(FUN)) if(FunName == "mean") { ... } else if(FunName == "median") { ... } } Using 'switch' is an alternative to 'i

[R] Using if statement on function

2010-06-28 Thread Etienne Stockhausen
Hello everybody, I'm trying to use a if-statment on a function. For a better understanding I want to present a small example: FUN=mean # could also be median,sd or any other function if (FUN == mean) plot(...) if (FUN == median) plot(...)