Assignment 1

Author

Tony Parkes

Published

August 27, 2026

Section 1: Basic Tibble Operations

x_1 <- 32 * 506
x_2 <- 506 / 32
df_1 <- tibble(x_1, x_2)

kable(df_1, 
      align = 'c', 
      col.names = c('Variable X_1', 'Variable X_2'), 
      format.args = list(big.mark = ",")) %>% 
  kable_classic()
Variable X_1 Variable X_2
16,192 15.8125
x_1 <- 192 * 506
x_2 <- 506 / 18
df_2 <- tibble(x_1, x_2)

kable(df_2, 
      align = 'c', 
      col.names = c('Variable X_1', 'Variable X_2'), 
      format.args = list(big.mark = ",")) %>% 
  kable_classic()
Variable X_1 Variable X_2
97,152 28.11111
x_1 <- 192 * 506
x_2 <- 506 / 18
x_3 <- x_1 * x_2
x_4 <- sqrt(x_3)
df_3 <- tibble(x_1, x_2, x_3, x_4)

kable(df_3, 
      align = 'c', 
      col.names = c('Variable X_1', 'Variable X_2', 'Variable X_3', 'Variable X_4'), 
      format.args = list(big.mark = ",")) %>% 
  kable_classic()
Variable X_1 Variable X_2 Variable X_3 Variable X_4
97,152 28.11111 2,731,051 1,652.589
df_4 <- df_3 %>% mutate(x_5 = log(x_3))

kable(df_4, 
      align = 'c', 
      col.names = c('Variable X_1', 'Variable X_2', 'Variable X_3', 'Variable X_4', 'Variable X_5'), 
      format.args = list(big.mark = ",")) %>% 
  kable_classic()
Variable X_1 Variable X_2 Variable X_3 Variable X_4 Variable X_5
97,152 28.11111 2,731,051 1,652.589 14.8202

Section 2: Motor Trend Car Road Tests (mtcars)

mtcars_summary <- mtcars %>% 
  summarize(
    avg_mpg = mean(mpg), 
    avg_wt = mean(wt)
  )

kable(mtcars_summary, 
      align = 'c', 
      col.names = c('Average MPG', 'Average Weight (1000 lbs)'), 
      digits = 2) %>% 
  kable_classic()
Average MPG Average Weight (1000 lbs)
20.09 3.22

Section 3: Economic Data Analysis (Virginia Unemployment)

2020 Data Summary

# Fetching the unemployment data for Virginia from 2000 onward
unemp_data_2020 <- tq_get(c("VIRG251URN"), get = "economic.data", from = "2000-01-01")

# Summarizing the data from January 2020 onward
unemp_summary_2020 <- unemp_data_2020 %>% 
  filter(date >= "2020-01-01") %>% 
  summarize(
    min_rate = min(price, na.rm = TRUE), 
    max_rate = max(price, na.rm = TRUE), 
    mean_rate = mean(price, na.rm = TRUE)
  )

# Generating the styled table
kable(unemp_summary_2020, 
      align = 'c', 
      col.names = c('Minimum Unemployment Rate', 'Maximum Unemployment Rate', 'Mean Unemployment Rate'), 
      digits = 2) %>% 
  kable_classic()
Minimum Unemployment Rate Maximum Unemployment Rate Mean Unemployment Rate
2.4 12.4 4.07

2022 Data Summary

# Fetching the unemployment data for Virginia from 2022 onward
unemp_data_2022 <- tq_get(c("VIRG251URN"), get = "economic.data", from = "2022-01-01")

# Summarizing the data from January 2022 onward
unemp_summary_2022 <- unemp_data_2022 %>% 
  filter(date >= "2022-01-01") %>% 
  summarize(
    min_rate = min(price, na.rm = TRUE), 
    max_rate = max(price, na.rm = TRUE), 
    mean_rate = mean(price, na.rm = TRUE)
  )

# Generating the styled table
kable(unemp_summary_2022, 
      align = 'c', 
      col.names = c('Minimum Unemployment Rate', 'Maximum Unemployment Rate', 'Mean Unemployment Rate'), 
      digits = 2) %>% 
  kable_classic()
Minimum Unemployment Rate Maximum Unemployment Rate Mean Unemployment Rate
2.5 4 3.22

Summary Analysis

The minimum unemployment and the mean are relatively flat for the period between 2000 and 2022 (minimum unemployment was 2.4% in 2000 compared to 2.5% in 2022; the mean during those timeframes is relatively stable as well, with the 2000 onward data summary showing a stable baseline compared to the 3.22% for 2022).

However, there was a drastic difference between the maximum unemployment values recorded in these chunks. The 2000-present timeframe recorded a historical pandemic maximum of 12.4%, compared to a maximum of only 4.0% within the 2022 window, showing a steep decline back to normalcy during that timeframe.

Visualization

unemp_data_2020 %>% 
  filter(date > "2020-01-01") %>% 
  ggplot(aes(x = date, y = price)) + 
  geom_line(color = "steelblue", linewidth = 1) + 
  labs(
    title = "Unemployment Rate in Hampton Roads", 
    subtitle = "Virginia Beach-Chesapeake-Norfolk MSA, January 2020-Present", 
    x = "Date", 
    y = "Unemployment Rate (%)"
  ) + 
  theme_minimal()