-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_05-final-data.R
More file actions
57 lines (45 loc) · 1.82 KB
/
Copy path_05-final-data.R
File metadata and controls
57 lines (45 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# _05-final-data.R
source("_00-setup.R")
#### read in and bind data ####
data<-dplyr::bind_rows(readr::read_rds("unverified-data-checked.rds") |>
dplyr::select(DATE_PST,
STATION_NAME,
STATION_NAME_FULL,
PARAMETER,
INSTRUMENT,
RAW_VALUE),
readr::read_rds("prev-yrs-wind-checked.rds")
) %>%
dplyr::distinct(.)
#### all stations ####
# save list of stations in year_to_validate with data:
all_stations<-data |>
dplyr::filter(lubridate::year(DATE_PST) == year_to_validate) |>
dplyr::group_by(STATION_NAME) |>
dplyr::filter(!is.na(RAW_VALUE)) |>
dplyr::distinct(STATION_NAME) |>
dplyr::arrange(STATION_NAME)
# save all_stations as rds
readr::write_rds(all_stations,
"all-stations.rds")
# save all_stations as csv
readr::write_csv(all_stations,
"all-stations.csv")
#### write station data ####
# create prepped-data folder if it doesn't already exist
ifelse(dir.exists(file.path("./prepped-data")),
"prepped-data folder already exists",
dir.create(file.path("./prepped-data"
)))
# Save each station's data to prepped-data folder
purrr::walk(readr::read_rds("all-stations.rds")$STATION_NAME,
function(x) {
# test
# x<-"Abbotsford A Columbia Street"
# end test
stn_data <- data %>%
dplyr::filter(STATION_NAME == x)
readr::write_rds(stn_data,
file.path("./prepped-data",
stringr::str_c(x, ".rds", collapse = "")))
})