Initial commit: illustrative R data pipeline
This commit is contained in:
26
scripts/05_convert_units.R
Normal file
26
scripts/05_convert_units.R
Normal file
@@ -0,0 +1,26 @@
|
||||
# 03_convert_units.R
|
||||
# Reads wide-format population CSV, pivots to long, converts thousands to
|
||||
# full unit count.
|
||||
|
||||
source("scripts/00_paths.R")
|
||||
|
||||
library(readr)
|
||||
library(tidyr)
|
||||
library(dplyr)
|
||||
|
||||
df <- read_csv(population_raw, show_col_types = FALSE)
|
||||
|
||||
df_long <- df |>
|
||||
pivot_longer(
|
||||
cols = jan:jun,
|
||||
names_to = "month",
|
||||
values_to = "value"
|
||||
) |>
|
||||
mutate(
|
||||
value = value * 1000,
|
||||
unit = "persons"
|
||||
)
|
||||
|
||||
write_csv(df_long, population_full)
|
||||
|
||||
cat("04_convert_units.R: thousands -> persons, wrote df_population_full.csv\n")
|
||||
Reference in New Issue
Block a user