Hello everybody, i have the following problem to write a function which recognizes depending on the parameter-inputs how many equations for the calculation in the function are needed.
Here is an example of my problem: "myfun" <- function(a, b, c, d) { k <- length(a) #here d = 3 for example, but how can i dynamically controll #my function and tell her to build equations eq1 to eq5 if d = 5? "eq1" <- function(a, b, y) { c[k-1] <- a[k-1] + b * y } "eq2" <- function(a, b, y) { c[k-2] <- a[k-2] + b * y } "eq3" <- function(a, b, y) { c[k-3] <- a[k-3] + b * y } "eq4" <- function(a, b, z) { 1 - sum(c(eq1(z), eq2(z), eq3(z), z)) } sol <- uniroot(eq4, lower=0, upper=1) } I hope my problems is explained clear enough. I would be very happy if you can give me some advice. best regards Andreas -- ______________________________________________ R-help@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.