LoslegenKostenlos loslegen

Returning many things

Functions can only return one value. If you want to return multiple things, then you can store them all in a list.

If users want to have the list items as separate variables, they can assign each list element to its own variable using zeallot's multi-assignment operator, %<-%.

glance(), tidy(), and augment() each take the model object as their only argument.

The Poisson regression model of Snake River visits is available as model. broom and zeallot are 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.

# Look at the structure of model (it's a mess!)
___

# Use broom tools to get a list of 3 data frames
list(
  # Get model-level values
  model = ___,
  # Get coefficient-level values
  coefficients = ___,
  # Get observation-level values
  observations = ___
)
Code bearbeiten und ausführen