
Allow the user to decide what they want to happen.

It is a good idea to make your functions as flexible as possible. The default value of this argument is FALSE so if we want to remove the missing values we need to specify na.rm = TRUE. If you type in the console ?sum you will see that there is an argument to specify whether missing values should be removed or not. This is because in our function we use the function sum() without specifying to ignore missing values. Here the vector b contains two missing values and the function average(b) returns NA. In this case it is the object avg that we created inside the function.ī <- c ( 1, NA, 4, 2, 7, NA, 8, 4, 9, 3 ) average ( b ) # NA To pass the value of an object outside of the function, you need to specify what you want to return() or what is the outpute of the function. You cannot use those objects outside the function and they will not appear in your Environment window. However, these objects are created only inside the environment of the function. For instance we are creating an object, avg. You can create new objects inside a function. What this means is that Arguments specified in a function become objects (or variables) passed inside the function

Then, inside the function we use the same letter x to calculate the sum() and length() of x. You can use whatever letter or string of letters you want, but a common notation is to use x for the object that is going to be evaluated by the function.

When creating a function, you need to specify what input arguments the function is able to take.
