Making choices choice operators vectors (solution)

NoteExercise

Create the following variables.

masses <- c(45.2, 36.1, 27.8, 81.6, 42.4)
counts <- c(26, 20, 12, 32, 16)
heights <- c(5.6, 3.9, NA, 8.6, 39.2)

Use them to print whether or not the following statements are TRUE or FALSE.

  1. Each value in masses is greater than 40.
  2. Each mass in masses is between 30 and 50.
  3. Each value in counts is not equal to 26.
  4. Either the value in masses is greater than 42 or the value in counts is less than 20.
  5. Each value in heights is NA.
  6. Each value in heights is greater than 6.
CautionOutput solution
  1. Each value in masses is greater than 40.
[1]  TRUE FALSE FALSE  TRUE  TRUE
  1. Each mass in masses is between 30 and 50.
[1]  TRUE  TRUE FALSE FALSE  TRUE
  1. Each value in counts is not equal to 26.
[1] FALSE  TRUE  TRUE  TRUE  TRUE
  1. Either the value in masses is greater than 42 or the value in counts is less than 20.
[1]  TRUE FALSE  TRUE  TRUE  TRUE
  1. Each value in heights is NA.
[1] FALSE FALSE  TRUE FALSE FALSE
  1. Each value in heights is greater than 6.
[1] FALSE FALSE    NA  TRUE  TRUE