GithubHelp home page GithubHelp logo

Comments (5)

walkerke avatar walkerke commented on August 18, 2024 2

Definitely. I'll keep this on the radar for version 0.4 which will default to the new 2012-2016 ACS estimates (when they come out).

from tidycensus.

dkyleward avatar dkyleward commented on August 18, 2024 1

That's fair. In my use case, I'm pulling ~30 variables. I actually attempted to left_join() a conversion table, but I kept getting a select less than one feature in get1index error. The workaround that finally solved the problem was to convert the sf object to a data frame, do the join, and then st_as_sf() to get it back.

That's unlikely to be a problem with tidyverse, but it would be nice to automate. I do get your design philosophy, though. Thanks for the consideration.

from tidycensus.

walkerke avatar walkerke commented on August 18, 2024 1

I've pushed this functionality in 83dfe95. The way this works is by supplying a named vector to the variables parameter in either get_acs() or get_decennial(). For example:

library(tidycensus)
pop10 <- get_decennial(geography = "state", variables = c(totalpop = "P0010001"))
head(pop10)

# A tibble: 6 x 4
  GEOID       NAME variable    value
  <chr>      <chr>    <chr>    <dbl>
1    01    Alabama totalpop  4779736
2    02     Alaska totalpop   710231
3    04    Arizona totalpop  6392017
4    05   Arkansas totalpop  2915918
5    06 California totalpop 37253956
6    08   Colorado totalpop  5029196

Or:

d15 <- get_acs(geography = "state", variables = c(totalpop = "B01003_001", medinc = "B19013_001"))
head(d15)

# A tibble: 6 x 5
  GEOID    NAME variable estimate   moe
  <chr>   <chr>    <chr>    <dbl> <dbl>
1    01 Alabama totalpop  4830620    NA
2    01 Alabama   medinc    43623   281
3    02  Alaska totalpop   733375    NA
4    02  Alaska   medinc    72515   838
5    04 Arizona totalpop  6641928    NA
6    04 Arizona   medinc    50255   211

And in wide form:

d15wide <- get_acs(geography = "state", 
                   variables = c(totalpop = "B01003_001", medinc = "B19013_001"), 
                   output = "wide")
head(d15wide)

# A tibble: 6 x 6
  totalpopE totalpopM medincE medincM       NAME GEOID
      <dbl>     <dbl>   <dbl>   <dbl>      <chr> <chr>
1   4830620        NA   43623     281    Alabama    01
2    733375        NA   72515     838     Alaska    02
3   6641928        NA   50255     211    Arizona    04
4   2958208        NA   41371     247   Arkansas    05
5  38421464        NA   61818     156 California    06
6   5278906        NA   60629     252   Colorado    08

@dkyleward would you mind testing and letting me know if this meets your needs, or if you have any suggestions?

from tidycensus.

walkerke avatar walkerke commented on August 18, 2024

I'll keep this in mind for the next release, though dplyr already handles this quite well. One of my design philosophies with tidycensus is to return data in the right format for manipulation within the tidyverse, but let the tidyverse packages do what they do best. As such:

inc <- get_acs(geography = "state", variables = "B19013_001") %>%
  mutate(variable = recode(variable, B19013_001 = "hhincome"))

or:

inc <- get_acs(geography = "state", variables = "B19013_001", 
               output = "wide") %>%
  rename(hhinc_est = B19013_001E, hhinc_moe = B19013_001M)

isn't that much more code, and gives users explicit control over what they are doing.

from tidycensus.

dkyleward avatar dkyleward commented on August 18, 2024

Perfect, thank you!

from tidycensus.

Related Issues (20)

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.