Last updated: 2026-02-15

Checks: 6 1

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.


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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 10507be. 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/FY25 Main Meter Data.xlsx
    Ignored:    data/building_list_FY25_updated.xlsx
    Ignored:    data/graph_data_life_exp.csv
    Ignored:    data/~$building_list_FY25.xlsx
    Ignored:    data/~$building_list_FY25_updated.xlsx
    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/kwh_main_annual.csv
    Ignored:    output/kwh_main_daily.csv

Untracked files:
    Untracked:  analysis/main_meter_processing.Rmd

Unstaged changes:
    Modified:   data/building_list_FY25.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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Purpose

This code loads and processes the data for individual buildings on the main meter, combines them into a single dataset, and summarizes the completeness of the data.

Load

library(tidyverse)
library(readxl)
library(DT)
# load names of tabs
sheet <- excel_sheets("./data/FY25 Main Meter Data.xlsx")

# applying sheet names to dataframe names
data <- lapply(setNames(sheet, sheet), 
                    function(x) 
                      read_excel("./data/FY25 Main Meter Data.xlsx", sheet=x))

# attaching all dataframes together
main_bldgs <- bind_rows(data, .id="Sheet") %>%
  rename(building = Sheet,
         date = Date, 
         kWh1 = 3,
         kWh2 = 4) %>%
  mutate(kwh = ifelse(is.na(kWh1), kWh2, kWh1),
         date = mdy(date)) %>%
  filter(date < ymd("2025-07-01"),
         date > ymd("2024-06-30")) %>%
  select(-kWh1, -kWh2) %>%
  mutate(month = month(date, label = TRUE),
         day = wday(date, label = TRUE)) %>%
  select(building, month, day, date, kwh)

Check

str(main_bldgs)
tibble [8,395 × 5] (S3: tbl_df/tbl/data.frame)
 $ building: chr [1:8395] "Althouse" "Althouse" "Althouse" "Althouse" ...
 $ month   : Ord.factor w/ 12 levels "Jan"<"Feb"<"Mar"<..: 7 7 7 7 7 7 7 7 7 7 ...
 $ day     : Ord.factor w/ 7 levels "Sun"<"Mon"<"Tue"<..: 2 3 4 5 6 7 1 2 3 4 ...
 $ date    : Date[1:8395], format: "2024-07-01" "2024-07-02" ...
 $ kwh     : num [1:8395] 339 346 351 344 336 212 223 362 370 384 ...

Summarize

# store main meter total kwh from PPL data
main_tot <- 11648808

annual_non_na <- main_bldgs %>%
  filter(!is.na(kwh)) %>%
  group_by(building) %>%
  summarize(non_na = n())

annual <- main_bldgs %>%
  group_by(building) %>%
  summarize(kwh = sum(kwh, na.rm = T),
            days = n()) %>%
  left_join(annual_non_na, by = "building") %>%
  mutate(perc_days = round((non_na/days)*100, digits = 0))

# which are the missing days?
annual_missing <- main_bldgs %>%
  filter(is.na(kwh)) %>%
  group_by(date) %>%
  summarize(n = n())

# store total for all submetered buildings
indiv_tot <- sum(annual$kwh)

# What proportion of the total is captured here?
indiv_tot / main_tot
[1] 0.3898098

Summary graphs

ggplot(main_bldgs, aes(x = month, y = kwh, fill = building)) +
  geom_col(position = "stack") +
  theme_bw() +
  labs(title = "Buildings with Submeters on the Main Meter",
       x = "",
       y = "Electricity use (kWh)")

# store buildings with over 90% days of data
comp_bldg <- filter(annual, perc_days > 90) 

ggplot(filter(main_bldgs, building %in% comp_bldg$building),
       aes(x = month, y = kwh, fill = building)) +
  geom_col(position = "stack") +
  theme_bw() +
  labs(title = "Buildings with Submeters on the Main Meter\n
       (those with electricity data for >90% of days)",
       x = "",
       y = "Electricity use (kWh)")

Tables

Note: I’m guessing CHW corresponds to central heating (?) This would be the part of Kaufman Hall that is associated with producing energy for the rest of campus.

Annual summary

datatable(annual, filter = 'top', rownames=FALSE,
          colnames = c("Building","Total kWh","# Days", "Days with data", "Days with data (%)"))

Daily data

datatable(select(main_bldgs, building, date, kwh),
          filter = 'top', rownames = FALSE, colnames = c("Building","Date","kWh"))

Export

write.csv(annual, "./output/kwh_main_annual.csv", row.names = F)
write.csv(main_bldgs, "./output/kwh_main_daily.csv", row.names = F)

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

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         readxl_1.4.3    lubridate_1.9.3 forcats_1.0.0  
 [5] stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5    
 [9] tidyr_1.3.0     tibble_3.2.1    ggplot2_3.5.0   tidyverse_2.0.0

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.34     magrittr_2.0.3    timechange_0.3.0 
 [9] evaluate_0.23     grid_4.3.2        fastmap_1.1.1     cellranger_1.1.0 
[13] rprojroot_2.0.4   workflowr_1.7.1   jsonlite_1.8.8    promises_1.2.1   
[17] fansi_1.0.6       crosstalk_1.2.1   scales_1.3.0      jquerylib_0.1.4  
[21] cli_3.6.2         rlang_1.1.3       ellipsis_0.3.2    munsell_0.5.0    
[25] withr_3.0.0       cachem_1.0.8      yaml_2.3.8        tools_4.3.2      
[29] tzdb_0.4.0        colorspace_2.1-0  httpuv_1.6.13     vctrs_0.6.5      
[33] R6_2.5.1          lifecycle_1.0.4   git2r_0.33.0      htmlwidgets_1.6.4
[37] fs_1.6.3          pkgconfig_2.0.3   pillar_1.9.0      bslib_0.6.1      
[41] later_1.3.2       gtable_0.3.4      glue_1.7.0        Rcpp_1.0.12      
[45] highr_0.10        xfun_0.41         tidyselect_1.2.0  rstudioapi_0.15.0
[49] knitr_1.45        farver_2.1.1      htmltools_0.5.7   labeling_0.4.3   
[53] rmarkdown_2.25    compiler_4.3.2