MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Scalable Data Processing in R

Lihat Kursus

Petunjuk latihan

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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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
Edit dan Jalankan Kode