O'Reilly logo

Data Mashups in R by Xiao-Yi Li, Jeremy Leipzig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Statistics of Foreclosure

Importing Census Data

The same parsing, rendering of shapefiles, and geocoding of foreclosure events reviewed up to this point can be done in a number of other platforms. The real strength of R is found in its extensive statistical functions and libraries.

The US Census Bureau collects an extensive range of socioeconomic data that are interesting for our purposes. We can download some data pertaining to total population and total housing units that are indexed by the same tracts we have used for our map. The FactFinder download center provides easy access to this data, as shown in Figure 2-1.

Then, select All Census Tracts in a CountyPennsylvaniaPhiladelphia CountySelected Detailed Tables, as shown in Figure 2-2.

Add the eight tables (P1,P13, P14, P31, P41, P53, P87,H33), click Next, download the file, and unzip it.

The Census Bureau page containing all census tracts data; Pennsylvania and Philadelphia County are selected from the drop-down menu

Figure 2-1. The Census Bureau page containing all census tracts data; Pennsylvania and Philadelphia County are selected from the drop-down menu

The Census Bureau page showing all available titles in the Philadelphia County region

Figure 2-2. The Census Bureau page showing all available titles in the Philadelphia County region

Import this data into R, and use the function str() to see the data contained in each column:

  > censusTable1<-read.table("dc_dec_2000_sf3_u_geo.txt",sep="|",header=TRUE) 
 > censusTable2<-read.table("dc_dec_2000_sf3_u_data1.txt",sep="|", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required