I have two functions with different parameters, let say function f
and function g
:
f <- function(a1, a2, a3, a4, a5) {
w <- a1+a2+a3+a4+a5
}
and
g <- function(x, y) {
z <- w*x*y
print(z)
}
I am trying to merge this two functions into one and all I can think is doing it like this:
m <- function(a1,a2,a3,a4,a5,x,y) {
w <- a1+a2+a3+a4+a5
z <- w*x*y
print(z)
}
The problem with function m
is that I find it too messy because of too much parameters.
My goal is that to create a function that will go through
f
first and then go throughg
and finally print the answer.
The reason that I want to do this is that, in my code there will be almost 3 to 5 functions (let say g
,h
,i
,j
,k
) all with different parameters. However, these functions will undergo the primary function first (function f
), and then will execute either one of g
,h
,i
,j
,k
, based on users input. I have the idea of using loop, but I didn't know which loop to apply.
For example, I have another function h
and i
:
h <- function(b,c) {
t <- w*b/c
print(z)
}
i <- function(d, e) {
v <- w+d*e
print(z)
}
The thing that I wanna do is that to create a single function (maybe using loop) from all this function. Function f
is the primary function (which means that this is the first thing to be execute) and then based on user input, it will either execute function g
,h
, or i
.