OneBite.Dev - Coding blog in a bite size

declare a function with multiple parameter in R

Code snippet on how to declare a function with multiple parameter in R

myfunc <- function(x, y, z) { 
  return(x + y - z) 
}

This code declares a function, named “myfunc”, which takes three parameters, x, y, and z. It then returns the result of x + y - z.

To break down this code step by step, the “function” keyword is used to declare a function in R. Following this keyword, the name of the function, “myfunc” is given in the parentheses. After that, the parameters of the function, x, y, and z, are listed in the parentheses. Finally, the code inside the curly braces is the code that will run when the function is called; in this case, it simply returns the sum of the three arguments, x, y, and z.

r