महिला उधारकर्ताओं का अनुपात उधार लेना
पिछले अभ्यास में, आपने year और race (या ethnicity) के आधार पर stratify किया था। हालाँकि, डेटा को partition करने के और भी कई तरीके हैं। इस अभ्यास और अगले में, आप year के अनुसार शहरी (urban) और ग्रामीण (rural) क्षेत्रों में महिला उधारकर्ताओं का अनुपात निकालेंगे। यह अभ्यास पिछले से थोड़ा अलग है क्योंकि यहाँ आपको केवल गिनती नहीं, बल्कि year पर निर्भर (conditioned) महिला उधारकर्ताओं का अनुपात चाहिए।
इस अभ्यास में, हमने एक फंक्शन परिभाषित किया है जो शहरी और ग्रामीण क्षेत्रों के लिए महिला उधारकर्ताओं का अनुपात निकालता है: female_residence_prop().
यह अभ्यास पाठ्यक्रम का हिस्सा है
R में Scalable Data Processing
अभ्यास निर्देश
- 2015 के लिए शहरी और ग्रामीण क्षेत्रों में महिला उधारकर्ताओं का अनुपात निकालने के लिए
female_residence_prop()कॉल करें:- पहला आर्ग्युमेंट डेटा है,
mort. - दूसरा आर्ग्युमेंट 2015 की rows से संबंधित एक logical वेक्टर है.
- पहला आर्ग्युमेंट डेटा है,
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
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
___(___, ___)