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()
.
Cet exercice fait partie du cours
Scalable Data Processing in R
Instructions
- 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.
- The first argument is the data,
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
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
___(___, ___)