Back
Close

Computing with Data

elgeish
60.8K views

Functions

Functions in R are similar to those in C++ and Java. When calling a function, the arguments flow into the function according to their order at the call site:

# foo is a user-defined function
foo = function(x = 1, y = 2, z = 3) {
return(x + y + z)
}
foo(10, 20, 30) # parameter bindings by order
foo(y = 20, x = 10, z = 30) # (potentially) out of order parameter bindings
foo(x = 10, y = 20, z = 30) # passing 3 parameters
foo(z = 30) # x and y are missing and are assigned default values
foo(10) # in-order parameter binding with last two parameters missing
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants