Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Evaluation

R is an http://en.wikipedia.org/wiki/Interpreted_Languageinterpreted language providing procedural, http://en.wikipedia.org/wiki/Functional_languagefunctional, 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 http://en.wikipedia.org/wiki/Functional_programmingfunctional 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 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

Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.