# Functions of functions in R

Developed with

5

## The course is part of this learning path

Fundamentals of R
11
3
1
1
Start course
Overview
Difficulty
Intermediate
Duration
27m
Students
55
Ratings
3.6/5
Description

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 or

Intended Audience

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

Pre-requisites

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

Feedback

Transcript

- We can use functions on functions say for example had to find a function called ' get number' which essentially gets a number or an index from the Fibonacci sequence which is defined as vector within the function As an aside this is bad practice and you should know to not define variables within functions However I am choosing to do so as part of the example that we are showing here on the screen Say I had to find another function called times two thirds where I take a input of X and I multiply it by two thirds So I'd like to just explain that functions can use can be used or called and they evaluate to the return value so if I was to take for example get number as the function to find here and called use that function with the input parameter 3, I would receive back the number 2 Now if I was to take the Fibonacci sequence and define it outside of the function in my global space as Fibbi and ask for the third entry to be returned I could say use the Fibbi and say the input parameters 3 I could verify that this doesn't make sense. I'm returning 2. So functions calls evaluate to the return values I could repeat the same sort of logic with my other function that I defined and I'd receive back the item 2 and that's the same as me taking functions and using the input of x as being 3 and asking for the return statement there. Now with respect to functions of functions We must know that function can be stacked. So say I had run get number is 8. And if I run through my fibinocci sequence within my get number function I would see that the eighth number in the FIB Vector is 21 I could then run or stack that 2/3 rd around or times 2/3 around this output of get number 8 which is 21 and I will see the result of 14 I can do this with built-in functions as well say around a norm on this and where the output of the times 2/3 rd of get number 8 is 14 . Hence I am stacking more and more functions together I can see that I will receive back 14 numbers on the screen ranging from 0 to 1 and the reason being for that is if I ask for the help on the unknown function in the help tab I can see that the description of this function is that it returns 14 or return n numbers to the screen number of observations returned

Kunal Haria
Data Science Trainer
Students
728
Labs
1
Courses
11
Learning Paths
1

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.