File tree 1 file changed +12
-4
lines changed 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -155,19 +155,27 @@ get_exclusions <- function(
155
155
}
156
156
157
157
data_substitutions <- function (dataset , disease , forecast_generation_date ) {
158
- disease <- " flu "
158
+ # Get the substitutions from the table, matched by forecast generation date
159
159
substitutions <- readr :: read_csv(
160
160
glue :: glue(" {disease}_data_substitutions.csv" ),
161
161
comment = " #" ,
162
162
show_col_types = FALSE
163
163
) %> %
164
164
filter(forecast_date == forecast_generation_date ) %> %
165
165
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 ) %> %
169
173
mutate(value = ifelse(! is.na(new_value ), new_value , value )) %> %
170
174
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 )
171
179
}
172
180
173
181
parse_prod_weights <- function (filename = here :: here(" covid_geo_exclusions.csv" ),
You can’t perform that action at this time.
0 commit comments