Adding variables to an existing spatial data frame

This recipe shows how you can add variables to spatial data frame objects. One approach (see the recipe Creating spatial data frames by combining regular data frames with spatial objects, earlier in this chapter) will be to create all the necessary variables before creating the spatial data frame object. However, this might not always be feasible. This recipe shows how you can add nonspatial variables to an existing spatial data frame object.

Getting ready

Install the sp, maps, and maptools packages. Download and place the nj-county-data.csv file in your R working directory.

How to do it...

To add variables to an existing spatial data frame, follow these steps:

  1. Follow the following steps shown (from ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.