Evaluating expressions
We now know how to enter code for R to interpret, whether directly entering it into R's command line or sending it to the command line from a code editor. Our next step will be to see how to use the simplest operations: arithmetic and logical operators and functions.
Using arithmetic and logical operators
The standard arithmetic operators in R are as follows:
+
: Addition-
: Subtraction*
: Multiplication/
: Division^
: Power
The following examples demonstrate the usage of these operators:
> 5+3 [1] 8 > 4-5 [1] -1 > 1*10 [1] 10 > 1/10 [1] 0.1 > 2^3 [1] 8
Parentheses can be used to construct more elaborate expressions, as follows:
> 2*(3+1) [1] 8 > 5^(1+1) [1] 25
It is better to use parentheses even when it is not required to make the ...
Get Learning R for Geospatial Analysis now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.