Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Evaluation

R is an interpreted language providing procedural, functional, and object oriented paradigms. The basic mode of interacting with R has the user typing commands (function names and arguments) and R evaluating them to return an answer (or an object). The object returned is often a vector (a collection of objects all of the same data type). The elements of the vector are numbered, beginning with 1, as indicated within the square brackets of the output. The returned elements are printed at the beginning of the line following the commands you type, but for brevity we include them as comments in our examples here (a comment is introduced with a # and continues to the end of a line):

> 5+2	                # [1] 7
> 5-2			# [1] 3
> 5*2			# [1] 10
> 5/2			# [1] 2.5
> 5%%2			# [1] 1     Remainder after division
> 5^2			# [1] 25
> 5^2-2*3		# (5^2) - (2*3)      [1] 19

All of these examples use in place function names (i.e., operators like + and -) with the arguments on either side and returns a vector of length 1.

Documentation relating to operator precedence is available with:

> help(Syntax)

R is most typically seen as a functional language, meaning that it works by calling functions, such as log (for calculating the logarithm of a number), and returning values from these functions. Functions often require arguments that give additional information to the function. Some arguments are optional, and can be introduced through giving the name of the argument, which can often be abbreviated, or missing altogether using the position to indicate the intent of the argument.



> log(1000)		# 6.907755
> log(1000, base=10)	# 3
> log(1000, b=10)	# 3 Command arguments can be abbreviated
> log(1000, 10)		# 3 Command arguments can be positional

In fact, even the in-place operators we saw above (e.g., 5+2) are just a syntactic abbreviation for a function call:

> "+"(5,2)    # 7 In-place operators are a syntactic convenience

We mentioned above that arguments to a function can often be abbreviated. An important exception is when the formal argument appears after a ``...'' argument in the formal usage. So, for example, the function paste has the argument Roption[]collapse, but looking at the help page indicates a usage of:

paste(..., sep = " ", collapse = NULL)

Thus, we can not, in this instance, abbreviate Roption[]collapse to Roption[]coll.



Subsections
Copyright © 2004-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010