Last updated: 2026-02-14

Checks: 7 0

Knit directory: dickinson_power/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20260107) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 4e6a88e. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store
    Ignored:    data/graph_data_life_exp.csv
    Ignored:    output/annual_kwh.csv
    Ignored:    output/building_check.csv
    Ignored:    output/building_check.xlsx
    Ignored:    output/daily_kwh.csv
    Ignored:    output/kwh_annual.csv
    Ignored:    output/kwh_daily.csv
    Ignored:    output/~$building_check.xlsx

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/building_summary.Rmd) and HTML (docs/building_summary.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd f2835df maggiedouglas 2026-02-14 adjust gitignore and improve data wrangling and main meter case study
html f2835df maggiedouglas 2026-02-14 adjust gitignore and improve data wrangling and main meter case study
Rmd c2d2f6e maggiedouglas 2026-02-07 project set up and preliminary analyses

Conversion factors

dollars_kwh <- 0.0813
co2_kg_kwh <- 0.299511787

Load libraries + data

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(DT)

kwh <- read.csv("./data/kwh_by_building.csv", strip.white = TRUE)
key <- read.csv("./data/building_list_FY25.csv", strip.white = TRUE)
kwh_daily <- read.csv("./data/FY25 PPL Electricity Data.csv", strip.white = TRUE)

Check

str(kwh)
'data.frame':   152 obs. of  4 variables:
 $ NAME        : chr  "100 S. West St." "100 S. West St." "100 S. West St." "100 S. West St." ...
 $ meter_origin: chr  "100 S West St" "102 S West St *Apt 1" "102 S West St *Apt 2" "102 S West St *Apt 3" ...
 $ kwh_tot     : int  12628 4609 4109 2070 7284 5457 3365 6181 5231 3948 ...
 $ kwh_count   : int  365 365 365 365 365 365 365 365 365 365 ...
str(key)
'data.frame':   133 obs. of  11 variables:
 $ type       : chr  "Res Hall - M" "Other" "Res Hall - M" "Res Hall - U" ...
 $ banner_code: chr  "1428" "1824" "1720" "1667" ...
 $ NAME       : chr  "100 S. West St." "119 W. High St. (1, 2, 3)" "133 N. College St." "133 W. High St. (2, 5)" ...
 $ occupant   : chr  "Students" "Visiting Faculty" "Students" "Students" ...
 $ address    : chr  "100 S. West St." "119 W. High St." "133 N. College St." "133 W. High St" ...
 $ date_constr: int  NA NA 1890 NA NA 1910 1910 NA NA NA ...
 $ date_acqd  : int  NA 2012 2004 NA 2001 1989 1987 NA 2022 NA ...
 $ date_reno  : int  NA NA 2019 NA NA 2019 2019 NA NA NA ...
 $ sqft       : int  7190 2240 2272 NA 1900 1476 1728 5825 2864 NA ...
 $ main_meter : int  0 0 0 0 0 0 0 0 0 0 ...
 $ rental     : int  1 0 0 1 0 0 0 1 1 1 ...
str(kwh_daily)
'data.frame':   55138 obs. of  6 variables:
 $ account_number: num  1e+09 1e+09 1e+09 1e+09 1e+09 ...
 $ meter_origin  : chr  "152 W Louther St *Apt 2" "152 W Louther St *Apt 2" "152 W Louther St *Apt 2" "152 W Louther St *Apt 2" ...
 $ meter_number  : int  300056642 300056642 300056642 300056642 300056642 300056642 300056642 300056642 300056642 300056642 ...
 $ date          : chr  "7/18/24" "7/19/24" "7/20/24" "7/21/24" ...
 $ total_kwh     : num  28 26.4 26.5 26.3 27.2 ...
 $ ave_temp      : int  78 76 78 81 75 78 80 79 76 76 ...

Join datasets

comb <- kwh %>%
  left_join(key, by = "NAME", relationship = "many-to-one")

# generate key for building info
comb_key <- comb %>%
  select(type, NAME, main_meter, date_constr, date_acqd, date_reno, sqft) %>%
  unique()

# generate key to connect meters to building names
meter_key <- comb %>%
  select(meter_origin, NAME)

Subset

res_hall_S <- filter(comb, type == "Res Hall - S")

Aggregate

agg <- res_hall_S %>%
  group_by(NAME, type) %>%
  summarize(kwh_tot = sum(kwh_tot, na.rm = TRUE),
            sqft = mean(sqft, na.rm = TRUE))
`summarise()` has grouped output by 'NAME'. You can override using the
`.groups` argument.

Transform

# different choices for rounding are okay, but need to implement round() successfully
trans <- agg %>%
  mutate(kwh_sqft = round(kwh_tot/sqft,digits = 2),
         dollars = round(kwh_tot*dollars_kwh, digits = 0),
         ghg_kgCO2 = round(kwh_tot*co2_kg_kwh, digits = 0)) %>%
  arrange(-kwh_tot) %>%
  select(-type)

Tables

datatable(trans,
          filter = 'top',
          rownames = FALSE)
buildings <- filter(key, type == "Res Hall - S") %>%
  arrange(main_meter, -sqft) %>%
  select(NAME, sqft, main_meter)

datatable(buildings,
          filter = 'top',
          rownames = FALSE)

Master data

agg_tot <- comb %>%
  group_by(type, NAME) %>%
  summarize(kwh_tot = sum(kwh_tot, na.rm = TRUE),
            sqft = mean(sqft, na.rm = TRUE)) %>%
  mutate(kwh_sqft = kwh_tot/sqft) %>%
  filter(is.finite(kwh_sqft))
`summarise()` has grouped output by 'type'. You can override using the
`.groups` argument.
write.csv(agg_tot, "./output/annual_kwh.csv", row.names = F)

trans_tot <- agg_tot %>%
  mutate(kwh_sqft = round(kwh_tot/sqft,digits = 2),
         dollars = round(kwh_tot*dollars_kwh, digits = 0),
         ghg_kgCO2 = round(kwh_tot*co2_kg_kwh, digits = 0)) %>%
  arrange(type, -kwh_tot) 

Format daily kwh data for downstream analysis

# Generate daily kwh data at the building level + join to building info
comb_daily <- kwh_daily %>%
  left_join(meter_key, by = "meter_origin", relationship = "many-to-one") %>%
  group_by(NAME, date) %>%
  summarize(kwh = sum(total_kwh, na.rm = TRUE),
           ave_temp = mean(ave_temp, na.rm = TRUE)) %>%
  filter(NAME != "") %>%
  left_join(comb_key, by = "NAME") %>%
  mutate(kwh_sqft = kwh/sqft,
         dollars = kwh*dollars_kwh,
         co2_kg = kwh*co2_kg_kwh)
`summarise()` has grouped output by 'NAME'. You can override using the
`.groups` argument.
comb_clean <- comb_daily %>%
  select(type, NAME, date, ave_temp, kwh, kwh_sqft) %>%
  filter(is.finite(kwh_sqft))

write.csv(comb_daily, "./output/daily_kwh.csv", row.names = F)

main_meter <- filter(kwh_daily, meter_origin == "W High St (37 Big Buildings)") %>%
  mutate(date = mdy(date),
         month = month(date, label = TRUE),
         day = wday(date, label = TRUE),
         dollars = total_kwh*dollars_kwh,
         co2_kg = total_kwh*co2_kg_kwh,)

# Check which buildings are and are not represented in the electricity data
comb_check <- kwh %>%
  full_join(key, by = "NAME", relationship = "many-to-one") %>%
  select(NAME, address, type, meter_origin, kwh_tot, sqft, main_meter, rental) %>%
  arrange(type, main_meter, NAME, -kwh_tot) %>%
  mutate(diagnosis = ifelse(main_meter == 1, "main meter",
                            ifelse((is.na(kwh_tot) & main_meter == 0), "missing electric",
                                   ifelse((kwh_tot > 0 & main_meter == 1), "double", 
                                          ifelse(is.na(type), "missing building", "")))))

write.csv(comb_check, "./output/building_check.csv", row.names = FALSE)

sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.7.8

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] DT_0.33         lubridate_1.9.3 forcats_1.0.0   stringr_1.5.1  
 [5] dplyr_1.1.4     purrr_1.0.2     readr_2.1.5     tidyr_1.3.1    
 [9] tibble_3.2.1    ggplot2_3.5.1   tidyverse_2.0.0 workflowr_1.7.1

loaded via a namespace (and not attached):
 [1] sass_0.4.8        utf8_1.2.4        generics_0.1.3    stringi_1.8.3    
 [5] hms_1.1.3         digest_0.6.37     magrittr_2.0.3    timechange_0.3.0 
 [9] evaluate_0.23     grid_4.3.2        fastmap_1.1.1     rprojroot_2.0.4  
[13] jsonlite_1.8.8    processx_3.8.3    whisker_0.4.1     ps_1.7.5         
[17] promises_1.2.1    httr_1.4.7        fansi_1.0.6       crosstalk_1.2.1  
[21] scales_1.3.0      jquerylib_0.1.4   cli_3.6.2         rlang_1.1.3      
[25] ellipsis_0.3.2    munsell_0.5.0     withr_3.0.0       cachem_1.0.8     
[29] yaml_2.3.8        tools_4.3.2       tzdb_0.4.0        colorspace_2.1-0 
[33] httpuv_1.6.13     vctrs_0.6.5       R6_2.5.1          lifecycle_1.0.4  
[37] git2r_0.33.0      htmlwidgets_1.6.4 fs_1.6.3          pkgconfig_2.0.3  
[41] callr_3.7.3       pillar_1.9.0      bslib_0.6.1       later_1.3.2      
[45] gtable_0.3.4      glue_1.7.0        Rcpp_1.1.0        xfun_0.41        
[49] tidyselect_1.2.0  rstudioapi_0.16.0 knitr_1.45        htmltools_0.5.7  
[53] rmarkdown_2.25    compiler_4.3.2    getPass_0.2-4