关于如何最好地使用 acs R 包,我有几个问题。在此先感谢您的帮助。
我想建立一个综合数据框,它是一个查找表,其中包含我可以从他们的 API 中为每个邮政编码获得的所有人口普查数据。目前我只是使用 R 代码查找几个单独的表,如下例所示。是否有更好的方法来查找所有可用表并自动构建数据表数据集并填充列名?我知道 acs.lookup 函数,但我想加载所有表并获取其邮政编码的数据。有没有办法从 acs.lookup 输出中获取所有表的列表,或者可能是可用表的完整列表?
我还想获得尽可能多的变量的未来投影数据。我想我可以使用上述方法使用多年(2014 年、2013 年、2012 年、2011 年)并使用 2014 年的 acs14lite R 包来计算我发现的预测。在我这样做之前,我想知道美国人口普查本身是否有未来的预测使用这个 ACS 数据还是别的什么?
创建用户指定的地理位置
使用所有邮政编码
zip_geo = geo.make(zip.code = "*")
创建比赛数据框
获取比赛数据
race.data = acs.fetch(geography=zip_geo, table.number = "B03002", col.names = "pretty", endyear = 2013, span = 5)
创建人口统计数据框
zip_demographics = data.frame(region = as.character(geography(race.data)$zipcodetabulationarea), total_population = as.numeric(estimate(race.data[,1])))
zip_demographics$region = as.character(zip_demographics$region)
转换为 data.frame
race_df = data.frame(white_alone_not_hispanic = as.numeric(estimate(race.data[,3])), black_alone_not_hispanic = as.numeric(estimate(race.data[,4])), asian_alone_not_hispanic = as.numeric(estimate( race.data[,6])), hispanic_all_races = as.numeric(estimate(race.data[,12])))
zip_demographics$percent_white = (race_df$white_alone_not_hispanic / zip_demographics$total_population * 100) zip_demographics$percent_black = (race_df$black_alone_not_hispanic / zip_demographics$total_population * 100) zip_demographics$percent_asian = (race_df$asian_alone_not_hispanic / zip_demographics$total_population * 100) zip_demographics$percent_hispanic = ( race_df$hispanic_all_races / zip_demographics$total_population * 100)