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.

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 ...

Start Free Trial

No credit card required