BaşlayınÜcretsiz Başlayın

Relative change in demographic trend

In the last exercise, you looked at the changes in borrowing across demographics over time. In this exercise, you'll look at the relative change in demographic trend. To do this, you'll normalize each group's trend by borrowing in the first year, 2008.

Bu egzersiz

Scalable Data Processing in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Get the first column of rydf as column1.
  • Loop over columns 1:8, normalizing them by dividing each column by the first column.
  • Plot Year on the x-axis and Proportion the y-axis, colored and grouped by the Race variable.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# View rydf
rydf

# Get the first column of rydf
column1 <- rydf[, 1]

# Normalize the first 8 columns
for(this_column in 1:8) {
  rydf[, this_column] <- rydf[, ___] / ___
}

# Convert the data to long format
rydf_long <- pivot_longer(rydf, -Race, names_to = "Year", values_to = "Proportion")

# Plot
ggplot(rydf_long, aes(x = ___, y = ___, group = Race, color = Race)) + 
    geom_line()
Kodu Düzenle ve Çalıştır