Two-bedroom stats, by rent category
Rent_Category Count Minimum Average Maximum
Above average 5 1630 1750 1920
Below average 7 1270 1376 1490

Code:

# Installing and loading required packages

if (!require("tidyverse"))
  install.packages("tidyverse")
if (!require("openxlsx"))
  install.packages("openxlsx")
if (!require("gtExtras"))
  install.packages("gtExtras")

library(tidyverse)
library(openxlsx)
library(gtExtras)

# Reading data from:
# https://www.huduser.gov/portal/datasets/fmr/smallarea/index.html#year2024

FMR <- read.xlsx(
  "https://www.huduser.gov/portal/datasets/fmr/fmr2024/fy2024_safmrs_revised.xlsx",
  sheet = 1)

# Making a list of Rutherford County ZIP codes

ZIPList <- c(
  "37127",
  "37128",
  "37129",
  "37130",
  "37132",
  "37085",
  "37118",
  "37149",
  "37037",
  "37153",
  "37167",
  "37086")

# Filtering for Rutherford ZIP codes and
# selecting columns of interest

FMR_RuCo <- FMR %>%
  filter(ZIP.Code %in% ZIPList) %>%
  select(ZIP.Code, SAFMR.0BR, SAFMR.1BR, SAFMR.2BR, SAFMR.3BR, SAFMR.4BR) %>% 
  distinct()

# Renaming the columns

colnames(FMR_RuCo) <- c("ZIP", "Studio", "BR1", "BR2", "BR3", "BR4")

# Averaging estimates

FMR_RuCo <- FMR_RuCo %>%
  mutate(ZIP_Average = (Studio + BR1 + BR2 + BR3 + BR4) / 5)

# Sorting in descending order by ZIP_Average

FMR_RuCo <- FMR_RuCo %>%
  arrange(desc(ZIP_Average))

# Averaging ZIP_Average

Average_ZIP_Average <- mean(FMR_RuCo$ZIP_Average)

# Categorizing by ZIP_Average

FMR_RuCo <- FMR_RuCo %>%
  mutate(
    Rent_Category = case_when(
      ZIP_Average > Average_ZIP_Average ~ "Above average",
      ZIP_Average == Average_ZIP_Average ~ "Average",
      ZIP_Average < Average_ZIP_Average ~ "Below average",
      .default = "Error"))

# Grouping and summarizing

Summary_BR2 <- FMR_RuCo %>% 
  group_by(Rent_Category) %>% 
  summarize(Count = n(),
            Minimum = min(BR2),
            Average = round(mean(BR2), 0),
            Maximum = max(BR2))

# Sorting the Summary_BR2 file in descending order

Summary_BR2 <- Summary_BR2 %>% 
  arrange(desc(Average))

# Making the table

Summary_BR2_table <- gt(Summary_BR2) %>% 
  tab_header("Two-bedroom stats, by rent category") %>%
  cols_align(align = "left") %>%
  gt_theme_538

# Showing the table

Summary_BR2_table