Skip to Content
Data Mashups in R
book

Data Mashups in R

by Jeremy Leipzig, Xiao-Yi Li
March 2011
Beginner to intermediate
40 pages
49m
English
O'Reilly Media, Inc.
Content preview from Data Mashups in R

Chapter 1. Mapping Foreclosures

Messy Address Parsing

To illustrate how to combine data from disparate sources for statistical analysis and visualization, let’s focus on one of the messiest sources of data around: web pages.

The Philadelphia sheriff’s office posts foreclosure auctions on its website each month. How do we collect this data, massage it into a reasonable form, and work with it? First, create a new folder (for example, ~/Rmashup) to contain our project files. It is helpful to change the R working directory to your newly created folder.

  #In Unix/MacOS
  > setwd("~/Documents/Rmashup/")
  #In Windows
  > setwd("C:/~/Rmashup/")

We can download this foreclosure listings web page from within R (or you may instead choose to save the raw HTML from your web browser):

  > download.file(url="http://www.phillysheriff.com/properties.html",
    destfile="properties.html") 

Here is some of this web page’s source HTML, with addresses highlighted:

    6321 Farnsworth St.
           62nd                                            Ward
    1,379.88 sq. ft.  BRT# 621533500  Improvements: Residential Property
    <br><b>
    HOMER SIMPSON
    &nbsp;   &nbsp;
    </b>   C.P. January Term, 2006  No. 002619 &nbsp; &nbsp; $27,537.87
    &nbsp;  &nbsp;  Phelan Hallinan & Schmieg, L.L.P.
     <hr />
    <center><b>      243-467           </b></center>
    1402 E. Mt. Pleasant Ave.
    &nbsp;   &nbsp;  50th                                            Ward
    approximately 1,416 sq. ft. more or less  BRT# 502440300 ...

The sheriff’s raw HTML listings are inconsistently formatted, but with the right regular expression we can identify street addresses: notice how they ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Graphing Data with R

Graphing Data with R

John Jay Hilfiger

Publisher Resources

ISBN: 9781449305574Errata Page