Define Custom Functions in R

In Python, we define a function using the def reserved word followed by optional parameters in parenthesis. The body of the function is indented (very important!).

This defines the function but does not execute the body of the function.

In the below example, we define a new function called greet() which will print Hello Dolly when called.

Create Your Free Account

Create a free account to access this content and join our community of learners.

You'll get access to:

  • Access the full tutorial
  • Join our learning community
  • Track your progress
  • Bookmark content for later