1. Learn
  2. /
  3. Courses
  4. /
  5. Defensive R Programming

Connected

Exercise

Using the stop() function

The stop() function is used to indicate that something is wrong.

Instructions 1/2

undefined XP
    1
    2
  • The function mean_age() calculates the mean age. Stop the execution if any of the ages are negative. You can test if any in vector is negative using the any() function, e.g. any(ages).