Statistical Analysis: an Introduction using R/R/Functions

Apart from numbers, perhaps the most useful named objects in R are functions. Nearly everything useful that you will do in R is carried out using a function, and many are available in R by default. You can use (or "call") a function by typing its name followed by a pair of round brackets. For instance, the start up text mentions the following function, which you might find useful if you want to reference R in published work: Many R functions can produce results which differ depending on arguments that you provide to them. Arguments are placed inside the round brackets, separated by commas. Many functions have one or more optional arguments: that is, you can choose whether or not to provide them. An example of this is the function. It can take an optional argument giving the name of an R add-on package. If you do not provide an optional argument, there is usually an assumed default value (in the case of, this default value is , i.e. provide the citation reference for the base package: the package which provides most of the foundations of the R language). Most arguments to a function are named. For example, the first argument of the citation function is named package. To provide extra clarity, when using a function you can provide arguments in the longer form name=value. Thus citation("base") does the same as citation(package="base") If a function can take more than one argument, using the long form also allows you to change the order of arguments, as shown in the example code below.