Not!
One last operator to introduce is !
or, Not. You have already seen a similar operator, !=
, so you might be able to guess what it does. Add !
in front of a logical expression, and it will flip that expression from TRUE
to FALSE
(and vice versa).
!TRUE
[1] FALSE
apple <- c(120.00, 120.08, 119.97, 121.88)
!(apple < 121)
[1] FALSE FALSE FALSE TRUE
The stocks
data frame is available for you to use.
This exercise is part of the course
Intermediate R for Finance
Exercise instructions
- Use
!
and a relational operator to know whenibm
is not above176
. - A new vector,
missing
, has been created, which contains missing data. - The function
is.na()
checks for missing data. Useis.na()
onmissing
. - Suppose you are more interested in where you are not missing data.
!
can show you this. Use!
in front ofis.na()
to show positions where you do have data.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# IBM range
___
# Missing data
missing <- c(24.5, 25.7, NA, 28, 28.6, NA)
# Is missing?
___
# Not missing?
___