2017-02-16 7 views
1

私のprevious questionに関する質問で、American Fact Finderからデータをダウンロードする方法を知りたいと思います。 American Fact Finder Deep-linking guideによると、リンクへのhttpパスはかなり規則的であり、時間の経過とともに一貫しています。米国、アラバマ州、およびオートーガ郡、アラバマ州のための2006-2008アメリカのコミュニティ調査 3年の推定値からRを使用してAmerican Fact Finderからデータをダウンロードするにはどうすればよいですか?

ディスプレイテーブルB07010:ディープリンクガイドは、テーブル、すなわちに取得する方法の例を示し http://factfinder.census.gov/bkmk/table/1.0/en/ACS/08_3YR/B07010/0100000US|0400000US01|05000 00US01001

しかし、私は私の現在の調査は、これらのスレッドに基づいて

R.

に「ダウンロード」に「ビュー」を変換する方法がわからないよ:

  1. Using R to download zipped data file, extract, and import data
  2. Using R to download zipped data file, extract, and import csv
  3. Exporting Data From Census 2010
  4. Download Census Data Using R
  5. How to use Census API to pull data

私は解決策に来るように私はこの記事を更新することがあります。

+0

私はこのことができますかどうかわからないんだけど、B07010 2005年から2009年には優れた 'ACSを介してアクセスすることができます'パッケージ。 – Tiernan

答えて

0

これは私が今までに見つけた最も効果的なソリューションです:

Manipulating and mapping US Census data in R using the acs, tigris and leaflet packages

library(tigris) 
library(acs) 
library(stringr) #to pad fips codes 
library(gdtools) 

#grab the spatial data (tigris) 
#note that you can use the county names inthe tigris package but not in the acs.fetch function from the ACS pacakge so I'm using FIPS numbers here. 
#Grab the spatial data 
counties<-c(5,47,61,81,85) 
#solve the 'an error occurred in the secure channel support' 
#firewall issue? #nope. 
#https://www2.census.gov/geo/tiger/GENZ2015/shp/ 
#download via chrome works fine. 
library(gdtools) #did not fix it. 
#libcurl may fix it 
#https://stackoverflow.com/questions/29688026/vb6-winhhtp-error-occurred-in-the-secure-channel-support 
library(curl) 
tracts<-tracts(state='NY', county = c(5,47,61,81,85), cb=TRUE) 
#It does! 

##----------------get the tabular data-------------------- 
#zevross.com/blog 
#get the tabular data 
#in order to do this, you will need an API key from the US Census. 

#Go to https://api.census.gov/data/key_signup.html 
#to request one (takes a minute or two) and then 
#use the api.key.install function in the `acs` package to use the key. 

api.key.install(key="GETYOUROWNKEEY") 
#make a geographic set to grab tabular data (acs) 
geo<-geo.make(state=c("NY"), county = c(5,47,61,81,85), tract = "*") 
#package not updated to 2013 data, so 2012 used as terminal year 
income<-acs.fetch(endyear=2012, span=5, geography=geo, table.number="B19001", col.names ="pretty") 
#pretty gives fully column names, not census abbreviation. 
#B19001_001 and *.017 are total income and income over $200k 
#what results is not data, but a list of what is available. 
names(attributes(income)) #shows what's available 
attr(income, "acs.colnames") 

#convert to data frame for merging. 
income_df<-data.frame(paste0(
          str_pad([email protected]$state,2,"left", pad="0"), 
          str_pad([email protected]$county,3,"left", pad = "0"), 
          str_pad([email protected]$tract,6,"left", pad="0")), 
          [email protected][,c(
            "Household Income: Total:", 
            "Household Income: $200,000 or more")], 
            stringsAsFactors=FALSE) 
            #that worked, 12/18/2017              
library(dplyr) #required for select 
income_df<-select(income_df, 1:3) 
rownames(income_df)<-1:nrow(income_df) 
names(income_df)<-c("GEOID","total","over_200") 
income_df$percent <-100*(income_df$over_200/income_df$total) 
#works!  
関連する問題