Python Certification Training for Data Scienc ...
- 75k Enrolled Learners
- Live Class
Functions in R can be user defined and in-built functions. To define a function, a name is assigned and the keyword function is used to denote the start of the function and its argument list. Functions are created using the function () directive and are stored as R objects just like anything else. In particular, they are R objects of class function. Functions can be passed as arguments to other functions. Functions can be nested, so that you can define a function inside another function.
A user-defined function is a function provided by the user of a program or environment in a context where the usual assumption is that functions are built into the program or environment.
The variable x is a formal parameter of the function. When the function is called, it is passed as an arguement that provides a value for the formal parameter.
There is a function called the repeat function which means to repeat a value a number of time. Repeat series is repeat 1:6 twice as you can see in the image. All this data can be created whenever required and elements of the series can also be repeated.
cbind function combines vector, matrix or data frame by columns. rbind function combines vector, matrix or data frame by rows.
Got a question for us?? Please mention them in the comments section and we will get back to you.