OneBite.Dev - Coding blog in a bite size

declare a simple function in R

Code snippet on how to declare a simple function in R

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

This is a simple function written in R which creates a new function named ‘my_function’. The function requires two arguments, named ‘x’ and ‘y’, to run. The function then adds these two arguments together, and returns the sum as the result. The line of code ‘return(x + y)’ gives the instruction for the function to return the sum of the two arguments. This function can then be called whenever it is needed, with any two desired arguments.

r