Session Ready
Exercise

Writing a simple function

Whilst there are packages that contain only data, typically packages are created to collect together functions for performing a specific task. If you need a refresher on writing functions you might want to review the course Writing Functions in R.

For your package you are going to keep the functions simple. You are going to create a package that produces custom summary output for your data.

Instructions
100 XP
  • Write a function, numeric_summary(), that takes two arguments, a vector x and the logical na.rm.
  • Include a check to your function so it fails with an error message if the vector x is not numeric.
  • The function should return a data.frame containing the minimum, median, standard deviation and maximum values.
  • Check that your function works using the Ozone column of the airquality data and removing missing values.