ComeçarComece de graça

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().

Este exercício faz parte do curso

Scalable Data Processing in R

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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
___(___, ___)
Editar e executar o código