Get startedGet started for free

Relational practice

In the video, Lore taught you all about different types of relational operators. For reference, here they are again:

  • > : Greater than
  • >=: Greater than or equal to
  • < : Less than
  • <=: Less than or equal to
  • ==: Equality
  • !=: Not equal

These relational operators let us make comparisons in our data. If the equation is true, then the relational operator will return TRUE, otherwise it will return FALSE.

apple <- 45.46
microsoft <- 67.88

apple <= microsoft
[1] TRUE
hello <- "Hello world"

# Case sensitive!
hello == "hello world"
[1] FALSE

micr and apple stock prices and two dates, today and tomorrow, have been created for you.

This exercise is part of the course

Intermediate R for Finance

View Course

Exercise instructions

  • Is apple larger than micr?
  • Check to see if apple and micr are not equal using !=.
  • Is tomorrow less than today?

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Stock prices
apple <- 48.99
micr <- 77.93

# Apple vs. Microsoft
___

# Not equals
___

# Dates - today and tomorrow
today <- as.Date(Sys.Date())
tomorrow <- as.Date(Sys.Date() + 1)

# Today vs. Tomorrow
___
Edit and Run Code