Skip to content
Justice Tech School

Functions

Create with function(). The last value is returned. Defaults and ... add flexibility.

Example
add <- function(a, b = 1) a + b
print(add(2))
print(add(2, 5))
greet <- function(name, ...) paste("Hello", name, ...)
print(greet("Ada", "!"))

Exercise

Default argument.

function(a, b  1)

Quiz Test

How does R return values?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.