Database Reference
In-Depth Information
Exploring “streets”
R has very strong support for vector subscripting. To access the first six foreclosures on our
list:
> streets[1:6]
[1] "6321 Farnsworth St." "5711 Anderson St." "1250 S. 24th
St."
[4] "1546 S. 26th St." "2401 Pennsylvania Ave." "812 S. 58th
St."
c() forms a vector from its arguments. Subscripting a vector with another vector does what
you'd expect—here's how to form a vector from the first and last elements of the list:
> streets[c(1,length(streets))]
[1] "6321 Farnsworth St." "7455 Ruskin Rd."
Here's how to select foreclosures that are on a “Place”:
> streets[grep("Place",streets)]
[1] "1430 Dondill Place" "370 Tomlinson Place" "8025 Pompey Place"
[4] "7330 Boreal Place" "2818 Ryerson Place" "8416 Suffolk Place"
To order foreclosures by street number, dispense with non-numeric characters, cast as numer-
ic, and use order() to get the indices.
> streets[order(as.numeric(gsub("[^0-9].+",'',streets)))]
[1] "21 S. 51st St." "22 E. Garfield St."
[3] "26 W. Manheim St." "26 N. Felton St."
[5] "30 S. 58th St." "31 N. Columbus Blvd."
...
[1259] "12122 Barbary Rd." "12223 Medford Rd."
[1261] "12430 Wyndom Rd." "12701 Medford Rd."
[1263] "12727 Medford Rd." "13054 Townsend Rd."
Obtaining Latitude and Longitude Using Yahoo
To plot our foreclosures on a map, we'll need to get latitude and longitude coordinates for
each street address. Yahoo Maps provides this functionality (called “geocoding”) as a REST-
enabled web service. Via HTTP, the service accepts a URL containing a partial or full street
address, and returns an XML document with the relevant information. It doesn't matter wheth-
er a web browser or a robot is submitting the request, as long as the URL is correctly format-
ted. The URL must contain an appid parameter and as many street address arguments as are
known.
Search WWH ::




Custom Search