Writing new functions
A function is an object loaded into the computer's temporary memory and can be activated (usually with specific arguments) to perform a certain action. So far, we have used predefined functions (from R's base packages; starting in Chapter 3, Working with Tables, we are going to use functions from other contributed packages). In this section, we will describe the structure of a function's definition and see how we can write our own functions.
Note that in this book you are not going to define that many functions and the functions you will define are going to be rather simple. The reason for this is that most of the time you will be learning new methods, rather than repeatedly applying a given method you developed (which would justify writing a function for it). However, in practice, wrapping your code to a function form is frequently useful in cases where you have developed a certain procedure you would like to apply routinely to different datasets.