2021年5月1日星期六

Fix variable number of parameters in function in R

I would like to fix a variable number of parameters with different values for a given function, while the remaining parameters stay variable in R, i.e. assuming to have a function e.g.

fun <- function(par) {  par[1]+2*par[2]+3^(par[3])-exp(par[4])  }  

I would like to call the function fun once, when e.g. par[1], par[4] are fixed with an value e.g. par[1]=3, par[4]=1 and par[2], par[3] should stay variable. Another time only one parameter e.g. par[3] should be fixed and the remaining parameters should be variable. Is it possible to define therefore a function so that I can choose the parameters which should be fixed with a certain value and the remaining parameters stay variable? How is this possible? I need this, because I have a function with lots of parameter e.g. 20, so the solution must be flexible. Thank you in advance!

https://stackoverflow.com/questions/67348128/fix-variable-number-of-parameters-in-function-in-r May 01, 2021 at 11:50PM

没有评论:

发表评论