Skip to content

Commit 30e804a

Browse files
authored
Merge pull request #45 from lm-hien/my-branch
Add year 2020 to `us_national_population`
2 parents 0605158 + f212a45 commit 30e804a

File tree

7 files changed

+33
-17
lines changed

7 files changed

+33
-17
lines changed

‎NEWS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Fixed data formatting of `paulist_missions`
2424
- Added `methodists` (#14)
2525
- Added data for the year 2020 in `us_state_populations` (#44)
26+
- Added the year 2020 in `us_national_population` (#45)
2627

2728
# historydata 0.1
2829

‎R/us-national-population.R‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Population of the United States, 1790-2010
1+
#' Population of the United States, 1790-2020
22
#'
33
#' Population figures for the entire United States of America from the decennial census.
44
#'
@@ -11,11 +11,14 @@
1111
#' \item \code{population}: population of the state or territory.
1212
#'
1313
#' }
14-
#' @format A data frame with 23 observations of 2 variables.
14+
#' @format A data frame with 24 observations of 2 variables.
1515
#' @references This dataset has been gathered by the
16-
#' \href{https://www.nhgis.org/}{NHGIS}. Minnesota Population Center,
17-
#' \emph{National Historical Geographic Information System: Version 2.0}
18-
#' (Minneapolis: University of Minnesota, 2011).
16+
#' \href{https://www.nhgis.org/}{NHGIS}.
17+
#' Steven Manson, Jonathan Schroeder, David Van Riper, Katherine Knowles, Tracy Kugler,
18+
#' Finn Roberts, and Steven Ruggles.
19+
#' \emph{IPUMS National Historical Geographic Information System: Version 19.0}
20+
#' [dataset]. Minneapolis, MN: IPUMS, 2024.
21+
#' \doi{10.18128/D050.V19.0}
1922
#' @examples
2023
#' head(us_national_population)
2124
#' if(require(ggplot2)) {

‎R/us-state-populations.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' Steven Manson, Jonathan Schroeder, David Van Riper, Katherine Knowles, Tracy Kugler,
2323
#' Finn Roberts, and Steven Ruggles.
2424
#' \emph{IPUMS National Historical Geographic Information System: Version 19.0}
25-
#' \[dataset\]. Minneapolis, MN: IPUMS, 2024.
25+
#' [dataset]. Minneapolis, MN: IPUMS, 2024.
2626
#' \doi{10.18128/D050.V19.0}
2727
#' @examples
2828
#' head(us_state_populations)
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
library(dplyr)
2-
us_state_populations <- read.csv(file.path("data-raw", "nhgis0011_ts_state.csv"),
2+
library(tidyr)
3+
4+
us_state_populations <- read.csv(file.path("data-raw", "nhgis0001_ts_nominal_state.csv"),
35
stringsAsFactors = FALSE)
6+
7+
census_year_pattern <- "A00AA(\\d{4})"
8+
49
us_national_population <- us_state_populations %>%
5-
select(year = YEAR,
6-
state = STATE,
7-
state_population = A00AA) %>%
10+
pivot_longer(
11+
cols = matches(sprintf("%s$", census_year_pattern)),
12+
names_to = "year",
13+
values_to = "population",
14+
names_pattern = census_year_pattern
15+
) %>%
16+
mutate(year = as.integer(year)) %>%
817
as_tibble() %>%
918
group_by(year) %>%
10-
summarize(population = sum(state_population, na.rm = TRUE))
19+
summarize(population = sum(population, na.rm = TRUE))
1120
usethis::use_data(us_national_population, overwrite = TRUE)

‎data/us_national_population.rda‎

-5 Bytes
Binary file not shown.

‎man/us_national_population.Rd‎

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/us_state_populations.Rd‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)