Yes!

perfect!


very best wishes

Robin


On May 9, 2005, at 09:13 am, Uwe Ligges wrote:

Robin Hankin wrote:

Hello Uwe

[snip]


I see, now the problem is much clearer, so what about:

f <- function(foo, int, x){
    lf <- length(foo)
    li <- length(int)
    l <- max(lf, li)
    if(l > lf) foo <- rep(foo, length = l)
    else if(l > li) int <- rep(int, length = l)
    values <- mapply(function(foo, int)
        do.call(foo, list(x+int)), foo, int)
    return(rowSums(values))
}


Uwe


best wishes
Robin
On May 9, 2005, at 08:34 am, Uwe Ligges wrote:
Robin Hankin wrote:

Hi
I have an application where my difficulty boils down to not
being able to define a function f() with the following properties:
f("sin",0:2,x)               #returns sin(x+0) + sin(x+1) + sin(x+2)
f(c("sin","cos"), 1:2,x)     #returns sin(x+1) + cos(x+2)
f(c("sin","cos","exp"),3,x)  #returns sin(x+3) + cos(x+3) + exp(x+3)
anyone?


Not really nice, but hopefully works:



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
 tel  023-8059-7743

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to