【问题标题】:Has anyone used append_geoid in TIGRIS to build a new data frame collecting the new census blocks?有没有人在 TIGRIS 中使用 append_geoid 来构建一个新的数据框来收集新的人口普查区块?
【发布时间】:2022-01-18 03:00:06
【问题描述】:

我正在寻找一种使用 tigris 在 R 中重新编码的方法。是否可以将其写入新数据框并添加与该地址相关的 2010 年人口普查区块?

机场

【问题讨论】:

    标签: r dataframe geocode tigris tidycensus


    【解决方案1】:

    我以前从不使用 tigris。我知道 tmaptools 可以完成这项任务,但如果没有一些标签,您可以使用数据框选项。

    为了解决这种情况,我将我的代码设为OpenStreetMap。您可以在此链接上查看构建您所需的所有信息。

    我使用的代码如下:

    x <- 1:370
    
    address_tidy <- tibble(
        accident_index = "accidents_tidy$accident_index[i]",
        geo_loc = "accidents_tidy$geo_loc[i]",
        xml.names = "(xml_name(xml_children(xml_children(open_map_xml))))",
        xml.text = "(xml_text(xml_children(xml_children(open_map_xml))))"
      )
    
    address_tidy <- address_tidy %>%
      filter(accident_index == "Greg")
    
    for (i in x) {
      open_map_url <- str_c(
        "https://nominatim.openstreetmap.org/search?q=",
        accident_index_loc_$geo_loc[i],
        "&format=xml&polygon=0&addressdetails=1"
      )
      
      open_map_xml <- read_xml(open_map_url)
      
      df <- tibble(
        accident_index = accident_index_loc_$accident_index[i],
        geo_loc = accident_index_loc_$geo_loc[i],
        xml.names = (xml_name(xml_children(xml_children(open_map_xml)))),
        xml.text = (xml_text(xml_children(xml_children(open_map_xml))))
      )
      
      address_tidy <- bind_rows(address_tidy, df)
      
    }
    
    write.csv(address_tidy, "address_tidy_part10.csv")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-13
      • 2011-09-03
      • 1970-01-01
      • 2021-11-14
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多