LoslegenKostenlos loslegen

Passing arguments with ...

Rather than explicitly giving calc_harmonic_mean() and na.rm argument, you can use ... to simply "pass other arguments" to mean().

The dplyr package is loaded.

Diese Übung ist Teil des Kurses

Introduction to Writing Functions in R

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Swap na.rm arg for ... in signature and body
calc_harmonic_mean <- function(x, na.rm = FALSE) {
  x %>%
    get_reciprocal() %>%
    mean(na.rm = na.rm) %>%
    get_reciprocal()
}
Code bearbeiten und ausführen