Comece agoraComece grátis

Joining data from an external data frame

When working with geographic data in R, you'll commonly want to join attribute information from an external dataset to it for mapping and spatial analysis. The sf package enables the use of the tidyverse *_join() functions for simple features objects for this purpose. In this exercise, you'll learn how to join data to a spatial dataset of legislative boundaries for the Texas House of Representatives that you've obtained using tigris.

Este exercicio faz parte do curso

Analyzing US Census Data in R

Ver curso

Instruções do exercicio

  • Get a dataset of legislative district boundaries for Texas using the state_legislative_districts() function.
  • Set the house parameter to "lower" to request data for the Texas House of Representatives.
  • Use the left_join() function to merge a dataset of Texas House representatives to their legislative district boundaries.

exercicio interativo prático

Tente este exercicio completando este código de exemplo.

# Get boundaries for Texas and set the house parameter
tx_house <- ___(___ = "TX", ___ = "lower", cb = TRUE)

# Merge data on legislators to their corresponding boundaries
tx_joined <- ___(___, tx_members, by = c("NAME" = "District"))

head(tx_joined)
Editar e Executar Código