LoslegenKostenlos loslegen

Adding multiple columns (I)

More often than not, you may want to add/update multiple columns by reference. There are two ways to do this in data.table:

  • LHS := RHS form
  • Functional form

In this exercise, you will add columns using the LHS := RHS form. In the LHS, you specify column names as a character vector and in the RHS, you specify values/expressions to be added inside list() (or the alias, .()).

Diese Übung ist Teil des Kurses

Data Manipulation with data.table in R

Kurs anzeigen

Anleitung zur Übung

Add two new columns (mean_duration and median_duration) by reference using the LHS := RHS form that calculates the mean and median of the duration column for every start_station.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Add columns using the LHS := RHS form
batrips[, ___, 
        by = start_station]
Code bearbeiten und ausführen