markdownrcensusapi数据(代码片段)

author author     2022-12-13     300

关键词:

---
title: "Census"
author: "Tim Kluis"
date: "4/11/2019"
output: html_document
---

```r setup, include=FALSE
knitr::opts_chunk$set(echo = TRUE)
```

## Census 

This is an overview of how to utilize TidyCensus for data analysis that requires demographic information. The censusapi tutorial can be found at https://cran.r-project.org/web/packages/censusapi/vignettes/getting-started.html. Additional online documentation can be found at https://www.census.gov/data/developers/data-sets.html.

## Load Required Libraries

```r libraries
install.packages("censusapi")
library(tidyverse) 		# General package for standardize R programming
library(censusapi)		# Simplified Census API package
library(sqldf) 			  # Package that allows SQL programming
library(RPostgreSQL) 	# Package that controls PostgreSQL Database
```

## Identify Census API Key

You need to apply with the Census to obtain an API key to access their online database

```r apikey, echo=FALSE
# Add key to .Renviron
Sys.setenv(CENSUS_KEY="e230244144eac2f1fd00198c98b15ecd1afcf6ad")

# Check to see that the expected key is output in your R console
Sys.getenv("CENSUS_KEY")
```

## Gather APIs available from Census

In order to know the APIs that are available to utilize you need to leverage the listCensusApisfunction.

```r apis
apis <- listCensusApis()
View(apis)
```


## Gather Varlists from Census

In order to know the variables that are available to utilize you need to leverage the listCensusMetadata function. You need to location the name from the apis dataframe to place in the function to determine the type = variables.

```r varlists
sahie_vars <- listCensusMetadata(name = "timeseries/healthins/sahie", 
    type = "variables")
head(sahie_vars)
```

## Gather Geographies to leveage from Census

In order to know the geography levels that are available to utilize you need to leverage the listCensusMetadata function. You need to locate the geography from the apis dataframe to place in the function to determine the type = geography.

```r geography
sahie_geos <- listCensusMetadata(name = "timeseries/healthins/sahie", 
    type = "geography")
head(sahie_geos)
```

## Gather Data from Census

In order to gather the data from the census you need to leverage the getCensus function. Key variables in the function are name, vars, region, time)

```r gatherdata
sahie_states <- getCensus(name = "timeseries/healthins/sahie",
    vars = c("NAME", "IPRCAT", "IPR_DESC", "PCTUI_PT"), 
    region = "state:*", 
    time = 2016)
head(sahie_states)
```


```r gatherdata2
sahie_counties <- getCensus(name = "timeseries/healthins/sahie",
    vars = c("NAME", "IPRCAT", "IPR_DESC", "PCTUI_PT"), 
    region = "county:*", 
    regionin = "state:01,02", 
    time = 2017)
head(sahie_counties, n=12L)
```

```r gatherdata3
sahie_years <- getCensus(name = "timeseries/healthins/sahie",
    vars = c("NAME", "PCTUI_PT"), 
    region = "state:01", 
    time = "from 2006 to 2017")
head(sahie_years)
```

python用于数据探索的python代码片段(例如,在数据科学项目中)(代码片段)

查看详情

pythonflask-数据库片段(代码片段)

查看详情

python数据帧选择数据(代码片段)

查看详情

pythongithub数据(代码片段)

查看详情

pythondfply数据(代码片段)

查看详情

html数据(代码片段)

查看详情

jsonjson数据(代码片段)

查看详情

sqlmerge数据(代码片段)

查看详情

textscraperwiki数据(代码片段)

查看详情

swift数据(代码片段)

查看详情

sqlrfm数据(代码片段)

查看详情

javatodoapp数据库代码(代码片段)

查看详情

ruby导入数据临时代码(代码片段)

查看详情

java可见时刷新片段数据(代码片段)

查看详情

从单个数据点解析数据(代码片段)

我有一个讨厌的数据集:+----+------------------------------------------------------------------------------+|PK|Medications|+----+------------------------------------------------------------------------------+|1| 查看详情

sqldba代码用于数据库(代码片段)

查看详情

sqldba代码用于数据库(代码片段)

查看详情

sqldba代码用于数据库(代码片段)

查看详情