mortify_cohort <- function(filtered_data, current_year) {
for (x in unique(filtered_data$age_group)) {
for (y in unique(filtered_data$race)) {
for (z in unique(filtered_data$sex)) {
mortality_cohort <-
filtered_data %>%
filter(age_group == x) %>%
filter(race == y) %>%
filter(sex == z) %>%
arrange(theta_mortality)
mortality_length <- nrow(education_cohort)
cohort_mortality <-
mortality_data %>%
filter(Year == current_year) %>%
filter(Age_Group == x) %>%
filter(Race == y) %>%
filter(Sex == z) %$%
multiply_by(Deaths / Population, mortality_length) %>%
rep(current_year, .)
if(length(cohort_mortality) > mortality_length) {
cohort_mortality <- cohort_mortality[1:mortality_length]
}
if(length(cohort_mortality) < mortality_length) {
cohort_mortality <-
length(cohort_mortality) %>%
subtract(mortality_length, .) %>%
rep(cohort_mortality[1], .) %>%
c(cohort_mortality)
}
mortality_cohort$date_of_death <- cohort_mortality
filtered_data %<>%
merge.data.frame(mortality_cohort, all.y = TRUE)
}
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.