เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

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.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Scalable Data Processing in R

ดูคอร์ส

คำแนะนำการฝึกหัด

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.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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
แก้ไขและรันโค้ด