Comparison operators

This page contains much of the very fundamental information about R that you need to interpret and use it effectively. You should look through all of it now, but you will also benefit from periodically returning to this page as well—your increased understanding will enable you to gain more insights from all of this.

1 The operators

R accepts a set of comparison conditions:

  • x == y: is x equal to y?; Race == "H"
  • x != y: is x not equal to y?; St != "SC"
  • x >= y: is x greater than or equal to y?; SAT >= 1000
  • x > y: is x greater than y?; SAT > 1200
  • x <= y: is x less than or equal to y?; SAT =< 1000
  • x < y: is x less than y?; SAT < 1000

2 Examples

We are going to provide some examples of how to use the the comparison operators. First, let’s define a few variables that we will use in those examples:

> names <- c("Scott", "Dave", "Lindsey", "Mackenzie")
> vals <- c(3, 0, 1, -2)
> min_score <- 1000

Here are some examples of these simple arithmetic operators:

> 900 == min_score
[1] FALSE
> 900 >= min_score
[1] FALSE
> 900 <= min_score
[1] TRUE