BaşlayınÜcretsiz Başlayın

Female Proportion Borrowing

In the last exercise, you stratified by year and race (or ethnicity). However, there are lots of other ways you can partition the data. In this exercise and the next, you'll find the proportion of female borrowers in urban and rural areas by year. This exercise is slightly different from the last one because rather than simply finding counts of things you want to get the proportion of female borrowers conditioned on the year.

In this exercise, we have defined a function that finds the proportion of female borrowers for urban and rural areas: female_residence_prop().

Bu egzersiz

Scalable Data Processing in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Call female_residence_prop() to find the proportion of female borrowers for urban and rural areas for 2015:
    • The first argument is the data, mort.
    • The second argument is a logical vector corresponding to the row numbers of 2015.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

female_residence_prop <- function(x, rows) {
    x_subset <- x[rows, ]
    # Find the proportion of female borrowers in urban areas
    prop_female_urban <- sum(x_subset[, "borrower_gender"] == 2 & 
                                 x_subset[, "msa"] == 1) / 
        sum(x_subset[, "msa"] == 1)
    # Find the proportion of female borrowers in rural areas
    prop_female_rural <- sum(x_subset[, "borrower_gender"] == 2 & 
                                 x_subset[, "msa"] == 0) / 
        sum(x_subset[, "msa"] == 0)
    
    c(prop_female_urban, prop_female_rural)
}

# Find the proportion of female borrowers in 2015
___(___, ___)
Kodu Düzenle ve Çalıştır