Skip to main content
It looks like you're using Internet Explorer 11 or older. This website works best with modern browsers such as the latest versions of Chrome, Firefox, Safari, and Edge. If you continue with this browser, you may see unexpected results.

R Software for Business Guide: Operate

Arithmetic Operators

R uses common arithmetic operators you may have seen elsewhere:

  • Plus: +
  • Minus: -
  • Times: *
  • Divided by: /​
  • To the power of: ^
  • The quantity: ()

Comparison Operators

Some of R's comparison operators differ from those in other languages:

  • Is equal to: ==
  • ​Is not equal to: !=​
  • Is greater than: >​
  • Is less than: <​
  • Is greater than or equal to: >=​
  • Is less than or equal to: <=

Logical Operators

Coordinate multiple comparison statements with logical operators:

  • And: &
  • Or: |
  • Not: !

The above operators work with statements that evaluate to TRUE or FALSE in R or with the values themselves:

  • True: TRUE or T
  • False: FALSE or F

Assignment Operators

R stores data in named objects.

Create an object by assigning data to a name. For clarity, it's conventional to assign with <-, but other operators exist:

  • Left assign: <- or =
  • Right assign: ->

RStudio, assigning the value 54 to the object 'dat' then assigning the value 1 to the object 'dat'

Names are unique. If you assign to a new name, R creates a new object. If you assign to an existing name, the old object and its content disappear, replaced by your new assignment. Overwriting any object in R is that easy, so keep an eye on RStudio's auto-suggest box to see if a function or another object already has the name you plan to use.

RStudio, populating auto-suggest for 'dat...'

Retrieve the content of an object by calling the object's name.

RStudio, calling the object 'dat'

An object name is interchangeable with its content. Try it in your code.

RStudio, add an object to a vector