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.
Deze oefening maakt deel uit van de cursus
Intermediate R for Finance
Oefeninstructies
- Use
!and a relational operator to know whenibmis 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.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# IBM range
___
# Missing data
missing <- c(24.5, 25.7, NA, 28, 28.6, NA)
# Is missing?
___
# Not missing?
___