Functions in R

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "\subsection{Functions in \textsf{R}} In this lab the function objects were already introduced, and some basic functions were applied. That was the case of the {\tt c()} funct...")
 
(Blanked the page)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
\subsection{Functions in \textsf{R}}
 
In this lab the function objects were already introduced, and some basic
 
functions were applied. That was the case of the {\tt c()} function
 
which concatenates several elements in a vector, the {\tt matrix()}
 
function which transforms a vector in a matrix, the {\tt which()}
 
function which reports the elements where a given logical prove is TRUE,
 
etc..
 
  
Functions in \textsf{R} are very easy to apply because the programming
 
is the same in all cases. Applying a function is as easy as to type the
 
name of the function immediately followed (without space) by circular
 
brackets. Inside the circular brackets, the arguments of the function
 
are specified. A imaginary function named {\tt ResourcesAssessment()}
 
could be applied by using the following code:
 
<<eval=FALSE>>=
 
ResourcesAssessment(Arg_1, Arg_2, ..., Arg_i, ..., Arg_n)
 
@
 
where {\tt Arg\_i} are the n arguments which defineing the function
 
options.
 
 
Not all arguments must be specified to apply the function, as some
 
arguments have default settings that are applied in the case that the
 
argument is not specified. Some arguments requires a single element to
 
be entered, but also vectors or even matrices, dataframes or other type
 
of objects can be arguments in a function, as shown above. Most of the
 
cases the argument must be entered by using its name. For instance, the
 
argument {\tt add=TRUE} controls in some graphical functions whether the
 
current plot is produced in a new chart or incorporated to the previous one.
 
 
A question that may arise at this point is the list of the available
 
functions in \textsf{R}, or even the total number of it. It is a
 
difficult question to answer, as the number of functions is continuously
 
increasing. There is a set of functions included with the basic
 
\textsf{R} software (core), but the number of functions can be increased
 
by installing new packages. New packages can be downloaded from the URL
 
address of \textsf{R}, or being installed directly from \textsf{RStudio}
 
in the "Packages" tab of the Graphical output window. Even though it is
 
enough with installing once the new packages, packages not included in
 
the core must be activated each time to be used in a new \textsf{R}
 
session by using the {\tt library()} function.
 
 
Even though the number of available functions is huge, should we be
 
interested in create a new one. It can be easily done in \textsf{R} but
 
it is far of the scope of this introductory lab.
 

Latest revision as of 17:13, 31 January 2015

Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export