File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -155,19 +155,27 @@ get_exclusions <- function(
155155}
156156
157157data_substitutions <- function (dataset , disease , forecast_generation_date ) {
158- disease <- " flu "
158+ # Get the substitutions from the table, matched by forecast generation date
159159 substitutions <- readr :: read_csv(
160160 glue :: glue(" {disease}_data_substitutions.csv" ),
161161 comment = " #" ,
162162 show_col_types = FALSE
163163 ) %> %
164164 filter(forecast_date == forecast_generation_date ) %> %
165165 select(- forecast_date ) %> %
166- rename(new_value = value )
167- dataset %> %
168- left_join(substitutions ) %> %
166+ rename(new_value = value ) %> %
167+ select(- time_value )
168+ # Replace the most recent values in the appropriate keys with the substitutions
169+ new_values <- dataset %> %
170+ group_by(geo_value ) %> %
171+ slice_max(time_value ) %> %
172+ inner_join(substitutions ) %> %
169173 mutate(value = ifelse(! is.na(new_value ), new_value , value )) %> %
170174 select(- new_value )
175+ # Remove keys from dataset that have been substituted
176+ dataset %> %
177+ anti_join(new_values , by = c(" geo_value" , " time_value" )) %> %
178+ bind_rows(new_values )
171179}
172180
173181parse_prod_weights <- function (filename = here :: here(" covid_geo_exclusions.csv" ),
You can’t perform that action at this time.
0 commit comments