Open ClaudiaHebert opened 7 months ago
Hi @ClaudiaHebert
Did you check to make sure that when you merged datasets by GEOID and tractid (see below), that the resulting dataset was able to match correctly?
For instance,
msp <- merge( msp.pop1, census.dat, by.x="GEOID", by.y="tractid" )
Look at head(msp)
. Does it look good? if not, check head(msp.pop1$GEOID)
and `head(census.dat$tractid)'
The GEOID and tractid entries tend to look almost identical, except for some locations there may be an extra zero as a placeholder in the front of the GEOID variable, but not tractid. This leads to no mergers being performed returning a null dataset.
If this seems to be the case, you need to use regex to remove the zero from GEOID so that it will have same format as tractid to make the merge. something like below may work
msp.pop1$GEOID<-sub( ".","", msp.pop1$GEOID )
@AntJam-Howell I was also having this issue and your suggestion worked, thanks so much for the help.
Unfortunately this has not seemed to fix it for me yet.
I ran the head function to check but not sure how to know if head(sd) looks "good." What should I be looking for?
I also added the code to remove the leading zero before the merge function and empty polygon check (see below) but am receiving the same error when I get to step 4 of transforming the sf map object to a spatial version.
sd.pop1$GEOID<-sub( ".","", sd.pop1$GEOID ) #remove leading zeros sd <- merge(sd.pop, census.dat, by.x="GEOID", by.y="tractid" )
sd <- sd[ ! st_is_empty( sd ) , ] class(sd)
Hi can you send me your rmd file? I will take a look Best
-- Anthony Howell Director, Center for Technology, Data, and Society, Associate Professor, Public Policy Arizona State University
On Mon, Apr 1, 2024 at 3:49 PM ClaudiaHebert @.***> wrote:
Unfortunately this has not seemed to fix it for me yet.
I ran the head function to check but not sure how to know if head(sd) looks "good." What should I be looking for?
I also added the code to remove the leading zero before the merge function and empty polygon check (see below) but am receiving the same error when I get to step 4 of transforming the sf map object to a spatial version.
sd.pop1$GEOID<-sub( ".","", sd.pop1$GEOID ) #remove leading zeros sd <- merge(sd.pop, census.dat, by.x="GEOID", by.y="tractid" )
sd <- sd[ ! st_is_empty( sd ) , ] class(sd)
— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/DS4PS/cpp-529-spr-2021/issues/29*issuecomment-2030708740__;Iw!!IKRxdwAv5BmarQ!eBUO7HtEx2J5-sgnIuHvjpPdvtocJZXSk6Yo7Ug_2t2R2OMJ1bkwSWNnOtUoHF-fn1mlYZSDErbDrhyHdSSugpwXwrkYOA$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y7YNWRQ7RHEK4Q2EMCLY3HP65AVCNFSM6AAAAABFPYCCY6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZQG4YDQNZUGA__;!!IKRxdwAv5BmarQ!eBUO7HtEx2J5-sgnIuHvjpPdvtocJZXSk6Yo7Ug_2t2R2OMJ1bkwSWNnOtUoHF-fn1mlYZSDErbDrhyHdSSugpxt95PWtw$ . You are receiving this because you were mentioned.Message ID: @.***>
Just want to restate the solution I sent you in case others need to see the solution.
You need to change
sd.pop1$GEOID<-sub( ".","", sd.pop1$GEOID ) #remove leading zeros
to
sd.pop$GEOID<-sub( ".","", sd.pop$GEOID ) #remove leading zeros
Hi @AntJam-Howell
I am just beginning Step 4 of Lab 4 and have run into an issue with this line of code converting the sf map version to an sp version: sd.sp <- as_Spatial( sd )
Everything up to this point works but when I run this one line I receive the error message "Error in (function (cond) : error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': subscript out of bounds"
I have been troubleshooting for a bit and can't figure it out. When I type class(sd) to check on the structure, it says that it is both "sf" and "data.frame" which I'm thinking might be part of the issue?
Help would be appreciated, thank you!