Functions are bits of code that perform a particular task and print or return its output to an object. Writing functions are particularly useful to avoid rewriting code over and over in your program; instead, you can write a function and every time you would like to perform that particular task, you can call that function. In fact, all the code we used so far in our examples call built-in or third-party R package functions.
For example, we ask for the mean of
x using the following code:
> x <- c(2, 6, 7, 12) > mean(x)  6.75
In the preceding code, we are actually asking R to call the
mean() function. Each function takes arguments. If you would like to know what arguments could be passed to a particular R function, you can consult the ...