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(dplyr)
library(readr)
##Read CSV, filter for FUEL 1 ONLY
read.csv("Case 3 and 4.csv")
## X NH3 CO2.Equi CO CH4 NO2 NOx
## 1 Fuel 1 C1 569309948 4.209020e+12 25145583260 77679539 24787354 163451219
## 2 Fuel 1 C2 564876943 4.158600e+12 25045065500 77108254 24681961 162727135
## 3 Fuel 2 C1 231225 4.281772e+09 65033792 208665 163748 868813
## 4 Fuel 2 C2 231225 4.281772e+09 65033792 208665 163748 868813
## 5 Fuel 5 C1 305806 2.141918e+09 14432938 107688 14897 97922
## 6 Fuel 5 C2 305806 2.141918e+09 14432938 107688 14897 97922
## 7 Fuel 9 C1 0 0.000000e+00 0 0 0 0
## 8 Fuel 9 C2 0 0.000000e+00 0 0 0 0
## Total.PM10 Total.PM2.5 Brake.PM10 Tire.PM10 Brake.PM2.5 Tire.PM2.5 SO2
## 1 26436351 23386104 338501490 131513722 42312670 19726956 21267348
## 2 26276721 23244894 334268184 129868962 41783496 19480250 21012590
## 3 35390 32560 255749 99362 31972 14910 14310
## 4 35390 32560 255749 99362 31972 14910 14310
## 5 14990 13253 173203 67288 21650 10093 16492
## 6 14990 13253 173203 67288 21650 10093 16492
## 7 0 0 140953264 54762784 17619152 8214380 0
## 8 0 0 145186636 56407528 18148332 8461086 0
## X.1 X.2 Total.Energy Total.HC X.3 X.4 Distance
## 1 NA Fuel 1 C1 5.79170e+16 895665794 NA Fuel 1 C1 15417615884
## 2 NA Fuel 1 C2 5.72232e+16 892024074 NA Fuel 1 C2 15224795608
## 3 NA Fuel 2 C1 5.77525e+13 614553 NA Fuel 2 C1 11648541
## 4 NA Fuel 2 C2 5.77525e+13 614553 NA Fuel 2 C2 11648541
## 5 NA Fuel 5 C1 3.01113e+13 544127 NA Fuel 5 C1 7888795
## 6 NA Fuel 5 C2 3.01113e+13 544127 NA Fuel 5 C2 7888795
## 7 NA Fuel 9 C1 8.67326e+15 0 NA Fuel 9 C1 6419949052
## 8 NA Fuel 9 C2 8.91187e+15 0 NA Fuel 9 C2 6612763182
data <- read.csv("Case 3 FC2040.csv")
filtered_data <- data %>% filter(Fuel.Type == 1)
# Select columns from "NH3" to the end
nh3_col_index <- which(colnames(filtered_data) == "NH3")
selected_data <- filtered_data[, nh3_col_index:ncol(filtered_data)]
# Calculate the sum of each column
sums <- colSums(selected_data, na.rm = TRUE)
# Create a new row with the sums
new_row <- as.data.frame(t(sums))
colnames(new_row) <- colnames(selected_data)
# Add NA values for the columns before "NH3"
new_row1 <- cbind(data.frame(matrix(NA, nrow = 1, ncol = nh3_col_index - 1)), new_row)
colnames(new_row)[1:(nh3_col_index - 1)] <- colnames(data)[1:(nh3_col_index - 1)]
# Bind the new row to the original data
new_data <- bind_rows(data, new_row1)
view(new_row1)
#--------------
filtered_data <- data %>% filter(Fuel.Type == 2)
# Select columns from "NH3" to the end
nh3_col_index <- which(colnames(filtered_data) == "NH3")
selected_data <- filtered_data[, nh3_col_index:ncol(filtered_data)]
# Calculate the sum of each column
sums <- colSums(selected_data, na.rm = TRUE)
# Create a new row with the sums
new_row2 <- as.data.frame(t(sums))
colnames(new_row) <- colnames(selected_data)
# Add NA values for the columns before "NH3"
new_row1 <- cbind(data.frame(matrix(NA, nrow = 1, ncol = nh3_col_index - 1)), new_row)
colnames(new_row)[1:(nh3_col_index - 1)] <- colnames(data)[1:(nh3_col_index - 1)]
# Bind the new row to the original data
new_data <- bind_rows(data, new_row2)
view(new_row2)