Ex 2.1: Grouped Summary

teach_ds :: Teaching data science with the tidyverse

Setup

library(tidyverse)
library(openintro)

loans <- loans_full_schema %>%
  mutate(
    homeownership = str_to_title(homeownership), 
    bankruptcy = if_else(public_record_bankrupt >= 1, "Yes", "No")
  ) %>%
  filter(annual_income >= 10) %>%
  select(
    loan_amount, homeownership, bankruptcy,
    application_type, annual_income, interest_rate
  )

loans
# A tibble: 9,976 × 6
   loan_amount homeownership bankruptcy application_type annual_income interes…¹
         <int> <chr>         <chr>      <fct>                    <dbl>     <dbl>
 1       28000 Mortgage      No         individual               90000     14.1 
 2        5000 Rent          Yes        individual               40000     12.6 
 3        2000 Rent          No         individual               40000     17.1 
 4       21600 Rent          No         individual               30000      6.72
 5       23000 Rent          No         joint                    35000     14.1 
 6        5000 Own           No         individual               34000      6.72
 7       24000 Mortgage      No         joint                    35000     13.6 
 8       20000 Mortgage      No         individual              110000     12.0 
 9       20000 Mortgage      No         individual               65000     13.6 
10        6400 Rent          No         individual               30000      6.71
# … with 9,966 more rows, and abbreviated variable name ¹​interest_rate
# ℹ Use `print(n = ...)` to see more rows

Exercise

Based on the applicants’ home ownership status, compute the number of applicants and the average loan amount. Display the results in descending order of number of applicants.

# add your answer here