Arithmetic and Boolean Operators and Values

Table 7-1 lists the basic operators.

Table 7-1. Basic R Operators

Operation

Description

x + y

Addition

x - y

Subtraction

x * y

Multiplication

x / y

Division

x ^ y

Exponentiation

x %% y

Modular arithmetic

x %/% y

Integer division

x == y

Test for equality

x <= y

Test for less than or equal to

x >= y

Test for greater than or equal to

x && y

Boolean AND for scalars

x || y

Boolean OR for scalars

x & y

Boolean AND for vectors (vector x,y,result)

x | y

Boolean OR for vectors (vector x,y,result)

!x

Boolean negation

Though R ostensibly has no scalar types, with scalars being treated as one-element vectors, we see the exception in Table 7-1: There are different Boolean operators for the scalar and vector cases. This may seem odd, but a simple ...

Get The Art of R Programming 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.