ipums_shape_left_join | R Documentation |
Helpers for joining shape files downloaded from the IPUMS website to data from extracts. Because of historical reasons, the attributes of (like variable type) of variables in the shape files does not always match those in the data files.
ipums_shape_left_join( data, shape_data, by, suffix = c("", "SHAPE"), verbose = TRUE ) ipums_shape_right_join( data, shape_data, by, suffix = c("", "SHAPE"), verbose = TRUE ) ipums_shape_inner_join( data, shape_data, by, suffix = c("", "SHAPE"), verbose = TRUE ) ipums_shape_full_join( data, shape_data, by, suffix = c("", "SHAPE"), verbose = TRUE )
data |
A dataset, usually one that has been aggregated to a geographic level. |
shape_data |
A shape file (loaded with |
by |
A vector of variable names to join on. Like the dplyr join functions, named vectors
indicate that the names are different between the data and shape file.
shape files to load. Accepts a character vector specifying the file name, or
|
suffix |
For variables that are found in both, but aren't joined on, a suffix to put on the variables. Defaults to nothing for data variables and "_SHAPE" for variables from the shape file. |
verbose |
I |
returns a sf or a SpatialPolygonsDataFrame depending on what was passed in.
# Note that these examples use NHGIS data so that they use the example data provided, # but the functions read_nhgis_sf/read_nhgis_sp perform this merge for you. data <- read_nhgis(ipums_example("nhgis0008_csv.zip")) if (require(sf)) { sf <- read_ipums_sf(ipums_example("nhgis0008_shape_small.zip")) data_sf <- ipums_shape_inner_join(data, sf, by = "GISJOIN") } if (require(sp) && require(rgdal)) { sp <- read_ipums_sp(ipums_example("nhgis0008_shape_small.zip")) data_sp <- ipums_shape_inner_join(data, sp, by = "GISJOIN") } ## Not run: # Sometimes variable names won't match between datasets (for example in IPUMS international) data <- read_ipums_micro("ipumsi_00004.xml") shape <- read_ipums_sf("geo2_br1980_2010.zip") data_sf <- ipums_shape_inner_join(data, shape, by = c("GEO2" = "GEOLEVEL2")) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.