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

Borrower Race and Ethnicity by Year (II)

In this exercise, you'll use both iotools and bigtabulate to tabulate borrower race and ethnicity by year.

Bu egzersiz

Scalable Data Processing in R

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

Egzersiz talimatları

iotools and bigtabulate are loaded in your workspace.

  • Create a function make_table() that reads in chunk as a matrix and then tabulates it by borrower race and year.
  • Use chunk.apply() to import the data from the file connection we created for you.
  • Convert race_year_table to a data frame.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Open a connection to the file and skip the header
fc <- file("mortgage-sample.csv", "rb")
readLines(fc, n = 1)

# Create a function to read chunks
make_table <- function(chunk) {
    # Create a matrix
    m <- ___(chunk, sep = ",", type = "integer")
    colnames(m) <- mort_names
    # Create the output table
    ___(m, c("borrower_race", "year"))
}

# Import data using chunk.apply
race_year_table <- ___(fc, make_table)

# Close connection
close(fc)

# Cast it to a data frame
rydf <- ___(race_year_table)

# Create a new column Race with race/ethnicity
rydf$Race <- race_cat
Kodu Düzenle ve Çalıştır