ComeçarComece de graça

Getting data for multiple states

In the previous exercise, you learned how to combine datasets with the rbind_tigris() function. If you need data for more than two states, however, this process can get tedious. In this exercise, you'll learn how to generate a list of datasets for multiple states with the tidyverse map() function, and combine those datasets with rbind_tigris().

Este exercício faz parte do curso

Analyzing US Census Data in R

Ver curso

Instruções do exercício

  • Generate a vector of state codes for Maine, New Hampshire, Vermont, and Massachusetts named new_england.
  • Use the tidyverse map() function to iterate through the vector of state codes.
  • Set the local variable x to request tract data for each state inside the function used by map().

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Generate a vector of state codes and assign to new_england
___ <- c("ME", "NH", "VT", "MA")

# Iterate through the states and request tract data for state
ne_tracts <- ___(new_england, function(x) {
  ___(state = ___, cb = TRUE)
}) %>%
  rbind_tigris()

plot(ne_tracts$geometry)
Editar e executar o código