Open ecking opened 4 years ago
@Anthony-Howell-PhD I'm completely stumped. Is this what coding life is life? Just banging your head against a wall? haha
Did you try "02" instead of "2"?
I can't recall how this function is implemented, but FIPS codes sometimes require you to be precise.
This will give you a character vector:
state.fips <- substr( these.fips, 1, 2 )
head( state.fips )
So this is your problem I believe:
state.fips <- "02"
state.fips == "02" # TRUE
state.fips == "2" # FALSE
And yes, this is coding life! But you start to enjoy the puzzles after awhile. Turns work into a sudoku game :-)
I can do sudoku for hours. But one can only deal with commas and 1s and 0s for so long. lol.
That was it. :-|
Thank you, Dr. Lecy.
Can someone please explain why I am getting this error? I want to talk about the San Jose-Santa Clara MSA for this assignment. This is just one of the many errors I have been getting all week D:
Can someone please explain why I am getting this error? I want to talk about the San Jose-Santa Clara MSA for this assignment. This is just one of the many errors I have been getting all week D:
My name is Archana by the way. I can't edit my username
@Niagara1000 The 27 in the example corresponds to Minnesota. You need to use the proper state code and the counties within your city. See below.
Make sure you include a reproducible example with your question so there is enough information to answer:
Include the code up to the point where you receive an error (see below), and copy your code into the discussion by placing it between "fences":
```r
# code goes here
Use the **Preview** option above to check your question before you post to make sure it is formatting correct.
Reproducible example:
```r
library( tidycensus )
# don't share your key on public boards
# key <- "abc123"
# census_api_key( key )
crosswalk <- read.csv( "https://raw.githubusercontent.com/DS4PS/cpp-529-master/master/data/cbsatocountycrosswalk.csv", stringsAsFactors=F, colClasses="character" )
these.msp <- crosswalk$msaname == "MINNEAPOLIS-ST. PAUL, MN-WI"
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 )
unique( state.fips )
[1] "27" "55"
# Minneapolis-St.Paul is located
# in two states so we need two calls,
# one for each state:
# state 27 = minnesota
# state 55 = wisconsin
counties.for.state.27 <- county.fips[ state.fips == "27" ]
counties.for.state.55 <- county.fips[ state.fips == "55" ]
# preview data
counties.for.state.27
[1] "003" "019" "025" "037" "053" "059" "123" "139" "141" "163" "171"
counties.for.state.55
[1] "093" "109"
msp.pop1 <-
get_acs( geography = "tract", variables = "B01003_001",
state = "27", county = counties.for.state.27, geometry = TRUE ) %>%
select( GEOID, estimate ) %>%
rename( POP=estimate )
msp.pop2 <-
get_acs( geography = "tract", variables = "B01003_001",
state = "55", county = counties.for.state.55, geometry = TRUE ) %>%
select( GEOID, estimate ) %>%
rename( POP=estimate )
msp.pop <- rbind( msp.pop1, msp.pop2 )
@Niagara1000 I've posted lab 4 solutions on the course website: https://ds4ps.org/cpp-529-spr-2020/schedule/
The solutions (.RMD) provide a very concise code-through that shows how to finish most parts of the lab, including how to update the code to create the red dot plots using 3 variables instead of 30 variables as shown in the Lab instructions. STEPS:
Two Minor Changes :
these.msp <- crosswalk$msaname == "MINNEAPOLIS-ST. PAUL, MN-WI"
msp.pop <- get_acs( geography = "tract", variables = "B01003_001",state = "27", county = county.fips[state.fips=="27"], geometry = TRUE ) %>% select( GEOID, estimate ) %>%rename( POP=estimate )
@lecy @Anthony-Howell-PhD Thank you for your detailed responses. It was super helpful to fix the code.
-Archana
Hello,
I'm in the first step on the lab and I have zero idea on what is wrong. I copied and pasted the code on the page... everything works. I go step by step using my state and it works until I get msp.pop section where all I'm doing is changing the code to "2."
I keep getting the error:
Getting data from the 2014-2018 5-year ACS Error: Your API call has errors. The API message returned is error: invalid 'in' argument.
Here is my code: