O'Reilly logo

Learning R for Geospatial Analysis by Michael Dorman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required