Input arguments of functions in R

Developed with
Start course

Course Description 

This module looks at functions, how to create functions, and how they can be used in R.  

Learning Objectives 

The objectives of this module are to provide you with an understanding of: 

  • How to define a function in R 
  • How to use built in functions in R  
  • What a return value is  
  • That functions can be stacked, and that they do not require an input 
  • That arguments can be named 

Intended Audience 

Aimed at all who wish to learn the R programming language. 


No prior knowledge of R is assumed. Delegates should already be familiar with basic programming concepts such as variables, scope, and functions. Experience of another scripting language such as Python or Perl would be an advantage. Understanding mathematical concepts will be beneficial.


We welcome all feedback and suggestions - please contact us at to let us know what you think. 


- [Instructor] Functions don't always require an input. Say I had to find a simulation of the throwing of a die and I would've liked to use that function, then with this function I could say, simulate the dice being thrown, or the die being thrown in this case. I could've also done the simulation just by using say for example, the code block here, in which I am taking a sample from the vector one to six of size one. But let's say I would've like to have used some inputs here for say, the size, and asked for a sample of size two because I'd like to see the number of dice being thrown. I could use for example, size equals two, and hope to see the results of two being returned, two specific sample points being returned from one to six. Unfortunately this will return the error, unused arguments. So functions don't always require an input. I could also have used say, I could've tried size equals to, to force this to occur, and again, R returns the error, reminding us that not always is a function requiring an input.

About the Author
Learning Paths

Kunal has worked with data for most of his career, ranging from diffusion markov chain processes to migrating reporting platforms.  

Kunal has helped clients with early stage engagement and formed multi week training programme curriculum. 

Kunal has a passion for statistics and data; he has delivered training relating to Hypothesis Testing, Exploring Data, Machine Learning Algorithms, and the Theory of Visualisation. 

Data Scientist at a credit management company; applied statistical analysis to distressed portfolios. 

Business Data Analyst at an investment bank; project to overhaul the legacy reporting and analytics platform. 

Statistician within the Government Statistical Service; quantitative analysis and publishing statistical findings of emerging levels of council tax data. 

Structured Credit Product Control at an investment bank; developing, maintaining, and deploying a PnL platform for the CVA Hedging trading desk.