始める無料で始める

借り手の人種・民族とその割合を比較する

この演習では、米国全体の人種・民族の割合と、人種・民族別の借り手の総数に占める割合を比較します。これは、各グループが米国内での人口割合に見合ったペースで借り入れているかを初歩的に確認するための作業です。前の演習とよく似ていますが、今回は iotools を使って実行します。

この演習はコースの一部です

Rで学ぶスケーラブルなデータ処理

コースを見る

演習の手順

  • "mortgage-sample.csv" の各チャンクから行列を作成します。
  • race_table_chunks のすべての列について、行を合計します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# 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]))
コードを編集して実行