Calling functions
One way to make your code more readable is to be careful about the order you pass arguments when you call functions, and whether you pass the arguments by position or by name.
gold_medals
, a numeric vector of the number of gold medals won by each country in the 2016 Summer Olympics, is provided.
For convenience, the arguments of median()
and rank()
are displayed using args()
. Setting rank()
's na.last
argument to "keep"
means "keep the rank of NA values as NA".
Best practice for calling functions is to include them in the order shown by args()
, and to only name rare arguments.
Diese Übung ist Teil des Kurses
Introduction to Writing Functions in R
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Look at the gold medals data
gold_medals
# Note the arguments to median()
args(median)
# Rewrite this function call, following best practices
median(TRUE,x=gold_medals)