Skip to content

Commit edf42d5

Browse files
authored
Merge pull request #9 from NSAPH-Data-Processing/issue-4
add padding for zipcode
2 parents a0458a1 + ef1871f commit edf42d5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

code/05_edit_data_types.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library(tidyverse)
2+
library(magrittr)
3+
library(lubridate)
4+
library(sf)
5+
library(dplyr)
6+
library(ggplot2)
7+
sf_use_s2(FALSE)
8+
9+
10+
# Loop through years 2006 to 2016
11+
for (year in 2006:2016) {
12+
# Construct file names for input and output CSV files
13+
input_file <- sprintf("../data/output/daily_zip_%d.csv", year)
14+
output_file <- sprintf("../data/output/daily_zip/daily_zip_%d.csv", year)
15+
16+
# Read in the input CSV file
17+
df <- read.csv(input_file)
18+
19+
# Convert zip column to character format with leading zeros
20+
df$zip <- sprintf("%05d", df$zip)
21+
22+
# Save modified data frame as new CSV file
23+
write.csv(df, output_file, row.names = FALSE)
24+
}

0 commit comments

Comments
 (0)