GithubHelp home page GithubHelp logo

danmalter / census Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 132 KB

R package to get US census data

Home Page: https://danmalter.github.io/census/

License: Other

R 22.43% HTML 77.57%
census-data census census-bureau

census's Introduction

census

Build Status CRAN Badge

census is a package for getting data from the Missouri Census Data Center. As of 2017, over 500 data points are available, including population, income, education and employment levels by age and race. Data can only be collected for cities and towns that have a population of 5,000 or more. An example of the data being collected from Missouri Census Data Center can be seen here.

census relies on the GoogleMaps API for retrieving latitude and longitude coordinates for specified cities. Google Maps allows for 2,500 free requests per day. Note that running a query on any given city too often over too short of a period can result in Google Maps API timeouts. If this happens, the getCensus function will skip that city. In addition, it is possible that a radius around a small town or city is too small and that there is no data provided by the Missouri Census Data Center. If this is the case, these particular cities will be skipped over as well and a warning message will show.

For more details, see Getting Started with Census and the package's website.

Installation

Get the latest stable release from CRAN:

install.packages("census")

Install the latest development version of census from Github using devtools:

# install.packages("devtools")
devtools::install_github("danmalter/census")

Usage examples

This example shows how to retrieve demographic data for the cities of Chicago and New York. This example only shows some of the over 500 features available. Note that the state is not needed in getCensus(), but you can run into problems if the city name appears in multiple states (i.e. Portland, Maine and Portland, Oregon).

library(census)

# City level data for Chicago and New York
radius <- 5
cities <- c("Chicago, IL", "New York")
df <- getCensus(cities, radius)
df[1:2, c("sitename","radius","TotPop","pctMales","pctFemales","AvgFamInc","pctPrivWageWorkers","pctGovWorkers", "pctMarried","pctBachelors","MedianHValue")]

#>  sitename  radius  TotPop      pctMales pctFemales AvgFamInc   pctPrivWageWorkers  pctGovWorkers pctMarried pctBachelors MedianHValue
#>  Chicago   5       756,255     49.3     50.7       $124,825    86.0                9.5           31.9       31.1         $365,867
#>  New York  5       2,269,840   48.6     51.4       $136,510    83.3                9.4           35.9       29.8         $782,702

If loading city and state information from a csv file, you can call that column into a list and run that list in getCensus().

radius <- 5
cities <- read.csv("~/path/to/file.csv")
cities <- c(as.character(cities$City_State))
df <- getCensus(cities, radius)
head(df)

To view Google Maps API usage limit. The below function is from the ggmaps package.

geocodeQueryCheck() 

Report an issue

If you have issues using, installing, and/or have a question about census, please post a new issue.

Disclaimer

This product uses the Google Maps API and collects data from the Missouri Census Data Center, but is not endorsed or certified by Google or the Missouri Census Data Center.

census's People

Contributors

danmalter avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ishandutta2007

census's Issues

issue

May be this is not an issue!, but when I ran the code attached to the package documentation I got this error:
library(census)

City level data for Chicago and New York

radius <- 5
cities <- c("Chicago, IL", "New York")
df <- getCensus(cities, radius)

Error in [.data.frame(geo.reply, , c("locality", "lon", "lat")) :
undefined columns selected
In addition: Warning messages:
1: geocode failed with status OVER_QUERY_LIMIT, location = "Chicago, IL"
2: geocode failed with status OVER_QUERY_LIMIT, location = "New York"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.