Introduction
Text values
Variables
Functions
17. Argument names
Summary

Instruction

Great! Lets go even further with arguments. Each function argument has an associated name.

round(14.356, 2)

In this call those argument names are x (14.356) and digits (2). You can use argument names in function call. In parentheses, first give the name of the argument, then the equality sign (=), and then the value of the argument. Here is an example for the round function:

round(x = 14.356, digits = 2)

If you use argument names, you can change the order of arguments, like this:

round(digits = 2, x = 14.356)

We've changed the order of the arguments x and digits such that the precision comes first. In this version of the function call, we must state the names of the arguments. Without the argument names, R would interpret the number we'd like to round as 2, based on its relative order in the argument list.

If you don't explicitly state the argument names, R will match them based on their relative positions and ordering.

Exercise

Round Tanya's weight in pounds (136.6864) to one decimal place. Use argument names when calling the appropriate function.