3. Operators

flowchart LR
    A((Objects)) --> B((Functions)) --> C((Operators))
    style C fill:#1a1a1a,stroke:#1a1a1a,color:#fff
    linkStyle default stroke:#adb5bd,stroke-width:2px

While R can be boiled down to objects and functions, it also does a good job handling mathematical calculations and logic.

The following commands are the basic arithmetic operators used in R.

Math Operator
Addition +
Subtraction -
Multiplication *
Division /
Exponent ^
Try it yourself — experiment with each math operator

Often, you will want to create an object with the help of some logical operators. The following are the logical operators used in R:

Logic Operator
Less Than <
Greater Than >
Less Than or Equal to <=
Greater Than or Equal to >=
Equal to ==
Not Equal to !=
Or \|
And &

For example, logical_test <- pie == pie_not_number

Run this example — logical comparisons return TRUE or FALSE

This returns a new class of logical that is either TRUE or FALSE.

Run this example — try and, or, and not operators

Click Next to review what you’ve learned and complete the Knowledge Check.