From a67a67b8d6680b139d69eb8ac5e140fd5d19b409 Mon Sep 17 00:00:00 2001 From: Nick Heppler Date: Fri, 10 Jan 2025 13:20:43 -0500 Subject: [PATCH] Initial commit. --- tree-tracker-aggregator.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tree-tracker-aggregator.R diff --git a/tree-tracker-aggregator.R b/tree-tracker-aggregator.R new file mode 100644 index 0000000..b9786a7 --- /dev/null +++ b/tree-tracker-aggregator.R @@ -0,0 +1,31 @@ +library(readr) +library(dplyr) +library(lubridate) + +# Read a delimited file into a tibble +data <- read_csv("Downloads/S123_69f6a2b6440848bab051f597ff4a8bf2_CSV/_25_Million_Trees_Initiative_Survey_0.csv") + +# Examine the column specifications for a data frame +spec(data) + +# Parse date-times with year, month, and day, hour, minute, and second components from col_character. +data <- data %>% + mutate( + `Start Date of Planting` = mdy_hms(`Start Date of Planting`), + `End Date of Planting` = mdy_hms(`End Date of Planting`) +) + +# Get/set months and years component of lanting date-time. +data <- data %>% + mutate( + plant_month = month(`Start Date of Planting`), # Extracts the month + plant_year = year(`Start Date of Planting`) # Extracts the year + ) + +# Group by municipality & county and summerize the total number of trees planted. +aggregated_data <- data %>% + group_by(`Year of Planting`, `Month of Planting`, Municipality, County) %>% + summarize(`Total Tree Plantings` = sum(`Number of Trees Planted`, na.rm = TRUE)) + +# View the aggregated data +print(aggregated_data) \ No newline at end of file