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
Exercise instructions
- Is
apple
larger thanmicr
? - Check to see if
apple
andmicr
are not equal using!=
. - Is
tomorrow
less thantoday
?
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
___