Skip to content

Commit

Permalink
Add spatial joins to if_else
Browse files Browse the repository at this point in the history
  • Loading branch information
Damonamajor committed Aug 7, 2024
1 parent e2f26d2 commit 5e990ec
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions analyses/Data_transformation.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,25 @@ if (type == "continuous") {
median(!!sym(target_feature_value), na.rm = TRUE),
!!paste0(target_feature_value, "_neighborhood_90th") :=
quantile(!!sym(target_feature_value), 0.9, na.rm = TRUE)
)
} else {
{
pin_nbhd <- pin_individual %>%
group_by(meta_nbhd_code, !!sym({{ target_feature_value }})) %>%
count() %>%
ungroup() %>%
group_by(meta_nbhd_code) %>%
mutate(percentage = n / sum(n) * 100) %>%
select(meta_nbhd_code, !!sym({{ target_feature_value }}), percentage) %>%
arrange(meta_nbhd_code, desc(percentage)) %>% # Arrange to have the highest percentage first
mutate(rank = row_number()) %>%
pivot_wider(
names_from = rank,
values_from = c(!!sym({{ target_feature_value }}), percentage),
names_glue = "{.value}_{rank}"
)
} %>%
) %>%
inner_join(nbhd, by = c("meta_nbhd_code" = "town_nbhd")) %>%
st_as_sf()
} else {{ pin_nbhd <- pin_individual %>%
group_by(meta_nbhd_code, !!sym({{ target_feature_value }})) %>%
count() %>%
ungroup() %>%
group_by(meta_nbhd_code) %>%
mutate(percentage = n / sum(n) * 100) %>%
select(meta_nbhd_code, !!sym({{ target_feature_value }}), percentage) %>%
arrange(meta_nbhd_code, desc(percentage)) %>% # Arrange to have the highest percentage first

Check warning on line 101 in analyses/Data_transformation.R

View workflow job for this annotation

GitHub Actions / pre-commit

file=/home/runner/work/model-res-avm/model-res-avm/analyses/Data_transformation.R,line=101,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 94 characters.
mutate(rank = row_number()) %>%
pivot_wider(
names_from = rank,
values_from = c(!!sym({{ target_feature_value }}), percentage),
names_glue = "{.value}_{rank}"
) %>%
inner_join(nbhd, by = c("meta_nbhd_code" = "town_nbhd")) %>%
st_as_sf() }

Check warning on line 109 in analyses/Data_transformation.R

View workflow job for this annotation

GitHub Actions / pre-commit

file=/home/runner/work/model-res-avm/model-res-avm/analyses/Data_transformation.R,line=109,col=14,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else.
}

# Pivot wider for leaflet maps to allow multiple shap values
Expand Down

0 comments on commit 5e990ec

Please sign in to comment.