Comparing the Borrower Race/Ethnicity and their Proportions
In this exercise, you'll compare the US race and ethnic proportions to proportion of total borrowers by race or ethnicity. This will provide an initial check to see if each group is borrowing at a rate comparable to its proportional representation in the United States. The task is similar to the last exercise, but this time you'll use iotools
to accomplish it.
This exercise is part of the course
Scalable Data Processing in R
Exercise instructions
- Create a matrix from each chunk of
"mortgage-sample.csv"
. - Add up the rows for all columns of
race_table_chunks
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create table of the borrower_race
race_table_chunks <- ___(
"mortgage-sample.csv", function(chunk) {
x <- ___(chunk, sep = ",", type = "integer")
colnames(x) <- mort_names
table(x[, "borrower_race"])
}, CH.MAX.SIZE = 1e5)
# Add up the columns
race_table <- ___(race_table_chunks)
# Find the proportion
borrower_proportion <- race_table[1:7] / sum(race_table[1:7])
# Create the matrix
matrix(c(pop_proportion, borrower_proportion), byrow = TRUE, nrow = 2,
dimnames = list(c("Population Proportion", "Borrower Proportion"), race_cat[1:7]))