OneBite.Dev - Coding blog in a bite size

declare a function with single parameter in R

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

  myFunc <- function(x) {
    # Put your code here
  } 

This code declares a function called “myFunc” which takes a single argument called “x”. Functions in R consist of the function assignment operator ” <- ”, the keyword “function”, parentheses ”( )” that contain the argument, and then brackets ”{ }” that contain the body of the function. In this example, the body of the function is blank, so the function does not do anything. To add instructions for the function, the code should be placed in between the curly brackets.

r