Efficient method for integrating multiple tables into a single data frame in r

I am trying to use the read_nhgis_sf to generate a single data frame in r.

Assume my zip file is:

nhgis0003_csv.zip

And it contains:

nhgis0003_ds120_1990_tract.csv

nhgis0003_ds120_1990_county_codebook.txt

nhgis0003_ds123_1990_tract.csv

nhgis0003_ds123_1990_tract_codebook.txt

How do I set up the data_layer command so that it integrates both tables into a single frame?

read_nhgis_sf(data_file, shape_file, data_layer = NULL,
shape_layer = data_layer, shape_encoding = “latin1”,
verbose = TRUE, var_attrs = c(“val_labels”, “var_label”, “var_desc”))

Can I integrate the codebooks as well?

Thank You

ipumsr does not include functionality to read multiple data layers at a time. However, the ipumsr functions read_nhgis_sf() and read_nhgis() return regular R data.frame objects, which can be combined in several ways that don’t rely on the ipumsr package. Thus the best approach would be to read the layers in one at a time and then combine them after reading. If the data layers all refer to the same geographic units, then you could use one of dplyr’s join functions to combine the data layers. If the data layers refer to different geographic units, but contain the same attributes for those units, then you could combine the data.frames with the bind_rows() function.

ipumsr also does not include functionality to read multiple codebooks at a time. It’s not clear what it would mean to “integrate” the codebooks. The function read_ipums_codebook() returns a list of information, some of which pertains to the extract more broadly, and some of which pertains to a specific data layer. If you combined the data layer data.frames by joining as described above, it might make sense to combine the corresponding var_info data.frame objects that are one element of the list returned by read_ipums_codebook(). Here’s some example code:

library(dplyr)
library(ipumsr)
codebook_1 <- read_ipums_codebook(cb_file, data_layer = data_layer_1)
codebook_2 <- read_ipums_codebook(cb_file, data_layer = data_layer_2)
combined_var_info <- bind_rows(codebook_1$var_info, codebook_2$var_info) %>%
    distinct(var_name, .keep_all = TRUE)

If you’d like more help, we likely need more information about the contents of the various data layers you want to combine, and what you are hoping the combined object(s) will look like. Feel free to follow up via email at ipums@umn.edu