Skip to content

Commit cf70eb6

Browse files
committed
ensure all tracts and all dates are in final data
1 parent 21b5950 commit cf70eb6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

inst/codec_data/xx_address/xx_address.R

+18-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,25 @@ shotspotter <-
4747
tally() |>
4848
rename(gunshots = n)
4949

50+
all_tracts <-
51+
cincy::tract_tigris_2010 |>
52+
st_drop_geometry() |>
53+
as_tibble() |>
54+
mutate(date = list(seq.Date(
55+
from = as.Date("2011-01-01"),
56+
to = as.Date("2024-06-01"),
57+
by = "month"
58+
))) |>
59+
tidyr::unnest(cols = c(date)) |>
60+
mutate(
61+
year = lubridate::year(date),
62+
month = lubridate::month(date)
63+
) |>
64+
select(-date)
65+
5066
d_out <-
51-
full_join(
52-
crime_incidents,
53-
shotspotter,
54-
by = c("census_tract_id_2010", "year", "month")) |>
67+
left_join(all_tracts, crime_incidents, by = c("census_tract_id_2010", "year", "month")) |>
68+
left_join(shotspotter, by = c("census_tract_id_2010", "year", "month")) |>
5569
mutate(
5670
across(c(property, violent, other, gunshots),
5771
\(x) ifelse(is.na(x), 0, x))) |>

0 commit comments

Comments
 (0)