DS4PS / cpp-529-fall-2020

http://ds4ps.org/cpp-529-fall-2020/
0 stars 0 forks source link

Error in Step 2 - Lab 04 #10

Open MeghanPaquette opened 4 years ago

MeghanPaquette commented 4 years ago

Hi @lecy,

I am getting an error message in step 2 of the lab. See the three code chunks. The first two groups of code are running correctly, but the last chunk is giving me the error below.

Thanks for any help, Meghan

ERROR : Your API call has errors. The API message returned is error: invalid 'in' argument.

crosswalk <- read.csv( "https://raw.githubusercontent.com/DS4PS/cpp-529-master/master/data/cbsatocountycrosswalk.csv",  stringsAsFactors=F, colClasses="character" )

# search for cities names by strings, use the ^ anchor for "begins with" 

grep( "^LAS", crosswalk$msaname, value=TRUE ) 
census_api_key("37aa351e003bee99f24badc29033cb17e1552ab0")

these.msp <- crosswalk$msaname == "LAS VEGAS, NV-AZ"
these.fips <- crosswalk$fipscounty[ these.msp ]
these.fips <- na.omit( these.fips )

state.fips <- substr( these.fips, 1, 2 )
county.fips <- substr( these.fips, 3, 5 )
vegas.pop1 <-
get_acs( geography = "tract", variables = "B01003_001",
         state = "27", county = county.fips[state.fips=="27"], geometry = TRUE ) %>% 
         select( GEOID, estimate ) %>%
         rename( POP=estimate )
kirstenronning commented 4 years ago

Hi, Meghan, I'm receiving the same error message. I think that it might have to do with changing the state = "27" to the corresponding number for our selected metro area. I believe it is the state's FIPS code.

MeghanPaquette commented 4 years ago

@kirstenronning Thank you! I was wondering the same thing, but couldn't figure out how to get those numbers. I did pander(state.fips) and it gave me two numbers. I plugged those in and it seems to work!

lecy commented 4 years ago

Thanks @kirstenronning. It was a little confusing because the get_census() function requires both county and state FIPS, but it can't be a vector. Ideally it would be able to use the state-county 5-digit version.

The code wasn't very explicit in the lecture notes, but the substring function was splitting state and county portions apart. As mentioned, you just need to change the state FIPS code in the API call.

> cbind( these.fips, state.fips, county.fips ) %>% pander()

---------------------------------------
 these.fips   state.fips   county.fips 
------------ ------------ -------------
   27003          27           003     

   27019          27           019     

   27025          27           025     

   27037          27           037     

   27053          27           053     

   27059          27           059     

   27123          27           123     

   27139          27           139     

   27141          27           141     

   27163          27           163     

   27171          27           171     

   55093          55           093     

   55109          55           109     
---------------------------------------