-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#106] added function populationExport
This function exports population data by agegroup and gender for each district.
- Loading branch information
1 parent
f829ef2
commit 5641a7f
Showing
4 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
populationExport <- function(sormas_db){ | ||
# This function outputs a table containing population data. | ||
# It contains data on the population by agegroup and gender in each district. | ||
|
||
# District table SQL query | ||
queryDistrict <- paste0("SELECT DISTINCT id AS district_id, | ||
name AS district_name | ||
FROM public.district | ||
WHERE archived = FALSE | ||
") | ||
districts <- DBI::dbGetQuery(sormas_db, queryDistrict) | ||
|
||
# Populationdata table SQL query | ||
queryPopulation <- paste0("SELECT DISTINCT id AS population_id, | ||
This comment has been minimized.
Sorry, something went wrong. |
||
district_id, | ||
region_id, | ||
sex AS sex_population, | ||
agegroup AS agegroup_population, | ||
population | ||
FROM public.populationdata | ||
") | ||
population_data <- DBI::dbGetQuery(sormas_db, queryPopulation) | ||
|
||
# Merging population data with district names | ||
population_data <- population_data %>% | ||
dplyr::left_join(., districts, by = 'district_id' ) | ||
|
||
#return output table | ||
return(population_data) | ||
} |
Population in sormas has regionname and district name, so we would need to find a way to merge by name