ComeçarComece de graça

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!

Este exercício faz parte do curso

Intermediate R for Finance

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Round 5.4
___

# Round 5.4 with 1 decimal place
___

numbers <- c(.002623, pi, 812.33345)

# Round numbers to 3 decimal places
___
Editar e executar o código