[R-sig-Geo] FIPS code join problem,

Roger Bivand Roger.Bivand at nhh.no
Mon Jan 2 09:51:03 CET 2012


On Fri, 30 Dec 2011, Juan Tomas Sayago wrote:

> Hello
> I am using the FIPS code for the joint between the county maps and the
> information, but I have a problem, the county fips have a problem with data
> joins with the codes like "01001" were omited cause when read by are in the
> data set became "1001". I am using this set code to make the join, if
> someone uses or do something different, please let me know.

The difference in string coding is usually caused by reading IDs as 
integer, then coercing to string directly, rather than using formatC() or 
alternatives:

> ID <- c(1001L, 01001L, 11001L)
# trailing L to enforce integer storage
> as.character(ID)
[1] "1001"  "1001"  "11001"
> formatC(ID, width=5, format="d")
[1] " 1001" " 1001" "11001"
> formatC(ID, width=5, format="d", flag="0")
[1] "01001" "01001" "11001"

There are examples of joining SpatialPolygonsDataFrame objects given in 
chapter 5 of our book, online resources at www.asdar-book.org.

Hope this helps,

Roger

>
> #### if you want to keep all polygons
>    tab <- tab[match(shpID,tabID),]
>      # matches both IDs and replaces nomatch values by NA
>    rownames(tab) <- shpID
>    shape.mod <- spCbind(shape,tab)
>
>
> Thanks
> Juan
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list