1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate R for Finance

Exercise

Optional arguments

Let's look at some of the round() function's help documentation. It simply rounds a numeric vector off to a specified number of decimal places.

round(x, digits = 0)

The first argument, x is required. Without it, the function will not work!

The argument digits is known as an optional argument. Optional arguments are ones that don't have to be set by the user, either because they are given a default value, or because the function can infer them from the other data you have given it. Even though they don't have to be set, they often provide extra flexibility. Here, digits specifies the number of decimal places to round to.

Explore the round() function in the exercise!

Instructions

100 XP
  • Use round() on 5.4.
  • Use round() on 5.4, specify digits = 1.
  • A vector numbers has been created for you.
  • Use round() on numbers and specify digits = 3.