시작하기무료로 시작하기

대출자 인종/민족과 그 비율 비교

이번 연습에서는 미국의 인종 및 민족 비율을 인종/민족별 전체 대출자 비율과 비교해 보세요. 이를 통해 각 집단이 미국 내 비율에 비해 유사한 수준으로 대출을 받는지 초기 점검을 할 수 있습니다. 과제는 직전 연습 문제와 유사하지만, 이번에는 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]))
코드 편집 및 실행