Syntax

R Define a Function Syntax

In R, define a function: defines a function — add <- function(a, b) { a + b }

Quick Answer

Syntax
add <- function(a, b) { a + b }
RSyntax

Define a Function

Code example
add <- function(a, b) { a + b }

Defines a function.

Learn More

How to define a function in R

  1. Open your R file or editor.
  2. Copy the example, then replace its sample names and values for your code.

R Define a Function Syntax

Use add <- function(a, b) { a + b }.

Related Syntax References

Frequently asked questions

What is the R syntax for define a function?

Use this pattern: add <- function(a, b) { a + b }

Can I copy this R code example?

Yes. Use Copy code and adapt the example to your program.

Is this R syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify