Matching arguments

In R functions, the arguments are the input variables supplied when you invoke the function. We can pass the argument, named argument, argument with default variable, or unspecific numbers of argument into functions. In this recipe, we will demonstrate how to pass different kinds of arguments to our defined function.

Getting ready

Ensure that you completed the previous recipe by installing R on your operating system.

How to do it...

Perform the following steps to create a function with different types of argument lists:

  1. Type the following code to your R console to create a function with a default value:
    >defaultarg<- function(x, y = 5){
    + y <- y * 2
    + s <- x+y
    + return(s)
    + }
    
  2. Then, execute the defaultarg user-defined function by ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.