R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(lubridate)
## Loading required package: timechange
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(ggplot2)
library(readxl)
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble  3.1.8     ✔ purrr   1.0.0
## ✔ tidyr   1.2.1     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ lubridate::as.difftime() masks base::as.difftime()
## ✖ lubridate::date()        masks base::date()
## ✖ dplyr::filter()          masks stats::filter()
## ✖ lubridate::intersect()   masks base::intersect()
## ✖ dplyr::lag()             masks stats::lag()
## ✖ lubridate::setdiff()     masks base::setdiff()
## ✖ lubridate::union()       masks base::union()
library(data.table)
## 
## Attaching package: 'data.table'
## 
## The following object is masked from 'package:purrr':
## 
##     transpose
## 
## The following objects are masked from 'package:lubridate':
## 
##     hour, isoweek, mday, minute, month, quarter, second, wday, week,
##     yday, year
## 
## The following objects are masked from 'package:dplyr':
## 
##     between, first, last
library(prettydoc)
library(readxl)
library(writexl)
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
df2<- ""
df3<- ""
df5<- ""
p <- ""
file1_path <- ""
file2_path <- ""
file3_path <- ""

merged_df <- ""

setwd("~/Documents/GitHub/Housing")

# Step 1: Read the two Excel files into data frames
file1_path <- "HousingCensus.xlsx"  # Replace with the actual file path
file2_path <- "Income.xlsx"  # Replace with the actual file path


file1_df <- read_excel(file1_path)
file2_df <- read_excel(file2_path)


# Step 2: Merge the data frames based on the "Name" field
merged_df <- left_join(file1_df, file2_df, by = "Name")


test1 <- lm(merged_df$`Change 2000 to 2020`~merged_df$income, merged_df)
summary(test1)
## 
## Call:
## lm(formula = merged_df$`Change 2000 to 2020` ~ merged_df$income, 
##     data = merged_df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40204 -0.06961 -0.01175  0.05536  0.60894 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       1.593e-01  1.039e-02  15.339   <2e-16 ***
## merged_df$income -3.671e-09  1.582e-07  -0.023    0.981    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1152 on 348 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  1.547e-06,  Adjusted R-squared:  -0.002872 
## F-statistic: 0.0005385 on 1 and 348 DF,  p-value: 0.9815

Including Plots

You can also embed plots, for example:

##```{r pressure, echo=FALSE}

# Create a Plotly scatter plot
scatter_plot <- plot_ly(merged_df, x = ~merged_df$income, y = ~merged_df$`Change 2000 to 2020`, type = "scatter", mode = "markers",
                        marker = list(size = 10, color = "blue"))

fig <- plot_ly(type = 'scatter', mode = 'markers') 
scatter_plot <- scatter_plot %>%
  add_trace(
   data = merged_df,
   x = ~merged_df$income, 
   y = ~merged_df$`Change 2000 to 2020`,
   text = merged_df$Name,
   hoverinfo = 'text',
   marker = list(color='black'),
   showlegend = F
   )



# Display the plot
scatter_plot
## Warning: Ignoring 1 observations

## Warning: Ignoring 1 observations
##plot(test2)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.