Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example of cens_margin_to() #2

Open
kuriwaki opened this issue Mar 28, 2024 · 1 comment
Open

example of cens_margin_to() #2

kuriwaki opened this issue Mar 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@kuriwaki
Copy link

The example provided in the function gives the following error. I also needed to flip the arguments in the example of cens_get_acs(). I have not been able to run this with ACS data yet (the example in README is for the decennial Census).

library(easycensus)
d_cens = cens_get_acs("B25042", "state") # example flips the order which won't work
d_cens
#> # A tibble: 780 × 6
#>    GEOID NAME    variable           estimate tenure          bedrooms          
#>    <chr> <chr>   <chr>                 <est> <fct>           <fct>             
#>  1 01    Alabama B25042_001E 1867893 ±  9539 total           total             
#>  2 01    Alabama B25042_002E 1284748 ± 12415 owner occupied  total             
#>  3 01    Alabama B25042_003E    4100 ±   628 owner occupied  no bedroom        
#>  4 01    Alabama B25042_004E   14578 ±  1257 owner occupied  1 bedroom         
#>  5 01    Alabama B25042_005E  168177 ±  5010 owner occupied  2 bedrooms        
#>  6 01    Alabama B25042_006E  739752 ±  8517 owner occupied  3 bedrooms        
#>  7 01    Alabama B25042_007E  292318 ±  5479 owner occupied  4 bedrooms        
#>  8 01    Alabama B25042_008E   65823 ±  2665 owner occupied  5 or more bedrooms
#>  9 01    Alabama B25042_009E  583145 ±  8764 renter occupied total             
#> 10 01    Alabama B25042_010E   17201 ±  1808 renter occupied no bedroom        
#> # ℹ 770 more rows

cens_margin_to(d_cens, bedrbedrooms)
#> Error in `dplyr::group_by()`:
#> ! Must group by variables found in `.data`.
#> ✖ Column `bedrbedrooms` is not found.
#> Backtrace:
#>     ▆
#>  1. └─easycensus::cens_margin_to(d_cens, bedrbedrooms)
#>  2.   ├─dplyr::summarize(...)
#>  3.   ├─dplyr::group_by(data, .data$GEOID, .data$NAME, ...)
#>  4.   └─dplyr:::group_by.data.frame(data, .data$GEOID, .data$NAME, ...)
#>  5.     └─dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
#>  6.       └─rlang::abort(bullets, call = error_call)

Created on 2024-03-28 with reprex v2.0.2

@CoryMcCartan
Copy link
Owner

Thanks, will fix this. The error in the reprex is because of the column name, but there's still an error when you pass the correct name bedrooms.

As a fix for now, if you run d_cens = dplyr::rename(d_cens, value=estimate), then cens_margin_to(d_cens, bedrooms) will work properly.

@CoryMcCartan CoryMcCartan added the bug Something isn't working label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants