Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learning R for Geospatial Analysis
Learning R for Geospatial Analysis

Learning R for Geospatial Analysis: Leverage the power of R to elegantly manage crucial geospatial analysis tasks

eBook
€28.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning R for Geospatial Analysis

Chapter 2. Working with Vectors and Time Series

In this chapter, we are going to cover the basic data structure in R—a vector. Understanding vectors is the foundation for all the subsequent chapters. You will learn how to perform efficient operations on numeric and logical vectors and how to create subsets. After this, you will learn how to write custom functions in order to expand and customize R's capabilities. Working with dates and time series and the use of graphical functions are introduced at the end of this chapter.

In this chapter, we'll cover the following topics:

  • Creating, saving, and examining the three main types of vectors
  • The principles of performing operations on vectors in R
  • Using functions that have more than one argument
  • Creating subsets of vectors
  • Dealing with missing values in vectors
  • Writing new functions
  • Working with dates
  • Displaying and saving graphical output

Vectors – the basic data structures in R

A vector is an ordered collection of values of the same type (or mode, in R terminology). As mentioned in the previous chapter, the three types of values that are useful for most purposes (including the topics of this book) are numeric, character, and logical. In this section, you are going to learn about several methods to create vectors, check the properties of interest for the given vectors, and perform operations involving pairs of vectors. You are also going to learn how to save the objects we create in the temporary computer memory via assignment.

Different types of vectors

Vectors are the most basic data structures in R since single elements (such as the number 10) are also represented in R by vectors (of length 1). As we have previously seen, when we enter a numeric value on the command line, it is printed on the screen. The number in square brackets to the left of the value is, in fact, the position of the leftmost element in the respective...

Using functions with several parameters

A function in R can have more than one parameter. In this section, we are going to get acquainted with supplying several arguments to such functions. At the same time, several new functions that take more than one argument will be introduced.

Supplying more than one argument in a function call

When specifying several arguments in a function, we need to assign each argument to the respective parameter using the usual assignment operator = during the function call, separating the assignment expressions for different parameters with commas.

For example, let's examine the seq function. Its most useful three parameters are from, to, and by (you can see in the function's help page that it has several more parameters). The seq function creates a sequential vector based on the input, as follows:

  • from: This parameter specifies from where to begin
  • to: This parameter specifies where to end
  • by: This parameter specifies the step size

Let's take a look...

Creating subsets of vectors

Creating subsets of data is one of the fundamental operations in data analysis. In this section, we will cover the two basic ways to create subsets of a vector. The first way involves numeric vectors, which specify the requested indices to be included in the subset. The second way involves using logical vectors, which specify for each element whether we would like to keep it or not.

Subsetting with numeric vectors of indices

Subsetting using numeric vectors of indices is done using the square brackets operator [, by providing the vector of indices within the square brackets. For example, we can select a single element of a vector by putting the value of the required index within brackets, as follows:

> x = c(5,6,1,2,3,7)
> x[3]
[1] 1
> x[1]
[1] 5
> x[6]
[1] 7

If we would like to, for example, find out the value of the last element in a given vector, we can use the length function, which returns its length (the index of the vectors' last element)...

Dealing with missing values

In this section, we are going to introduce the representation of missing values in R and ways to deal with them. Missing values can arise in many situations during data collection and analysis, either when the required information could not be acquired for some reason or when, due to certain circumstances, we would like to exclude some data from an analysis by marking them as missing. In the spatial data analysis context, it can be that some districts in an area we surveyed were inaccessible for data collection by the researcher or some parts of an aerial image were clouded and we could not digitize features of interest there.

Missing values and their effect on data

The special value that marks missing values in R is NA. As briefly mentioned in the previous chapter, NaN values represent cases when the resulting value cannot be represented within the real system number. NaN values function in the same way as NA in all respects that are relevant here.

The same way...

Writing new functions

A function is an object loaded into the computer's temporary memory and can be activated (usually with specific arguments) to perform a certain action. So far, we have used predefined functions (from R's base packages; starting in Chapter 3, Working with Tables, we are going to use functions from other contributed packages). In this section, we will describe the structure of a function's definition and see how we can write our own functions.

Note that in this book you are not going to define that many functions and the functions you will define are going to be rather simple. The reason for this is that most of the time you will be learning new methods, rather than repeatedly applying a given method you developed (which would justify writing a function for it). However, in practice, wrapping your code to a function form is frequently useful in cases where you have developed a certain procedure you would like to apply routinely to different datasets.

Defining...

Vectors – the basic data structures in R


A vector is an ordered collection of values of the same type (or mode, in R terminology). As mentioned in the previous chapter, the three types of values that are useful for most purposes (including the topics of this book) are numeric, character, and logical. In this section, you are going to learn about several methods to create vectors, check the properties of interest for the given vectors, and perform operations involving pairs of vectors. You are also going to learn how to save the objects we create in the temporary computer memory via assignment.

Different types of vectors

Vectors are the most basic data structures in R since single elements (such as the number 10) are also represented in R by vectors (of length 1). As we have previously seen, when we enter a numeric value on the command line, it is printed on the screen. The number in square brackets to the left of the value is, in fact, the position of the leftmost element in the respective...

Using functions with several parameters


A function in R can have more than one parameter. In this section, we are going to get acquainted with supplying several arguments to such functions. At the same time, several new functions that take more than one argument will be introduced.

Supplying more than one argument in a function call

When specifying several arguments in a function, we need to assign each argument to the respective parameter using the usual assignment operator = during the function call, separating the assignment expressions for different parameters with commas.

For example, let's examine the seq function. Its most useful three parameters are from, to, and by (you can see in the function's help page that it has several more parameters). The seq function creates a sequential vector based on the input, as follows:

  • from: This parameter specifies from where to begin

  • to: This parameter specifies where to end

  • by: This parameter specifies the step size

Let's take a look at the following...

Creating subsets of vectors


Creating subsets of data is one of the fundamental operations in data analysis. In this section, we will cover the two basic ways to create subsets of a vector. The first way involves numeric vectors, which specify the requested indices to be included in the subset. The second way involves using logical vectors, which specify for each element whether we would like to keep it or not.

Subsetting with numeric vectors of indices

Subsetting using numeric vectors of indices is done using the square brackets operator [, by providing the vector of indices within the square brackets. For example, we can select a single element of a vector by putting the value of the required index within brackets, as follows:

> x = c(5,6,1,2,3,7)
> x[3]
[1] 1
> x[1]
[1] 5
> x[6]
[1] 7

If we would like to, for example, find out the value of the last element in a given vector, we can use the length function, which returns its length (the index of the vectors' last element), as follows...

Left arrow icon Right arrow icon

Description

This book is intended for anyone who wants to learn how to efficiently analyze geospatial data with R, including GIS analysts, researchers, educators, and students who work with spatial data and who are interested in expanding their capabilities through programming. The book assumes familiarity with the basic geographic information concepts (such as spatial coordinates), but no prior experience with R and/or programming is required. By focusing on R exclusively, you will not need to depend on any external software—a working installation of R is all that is necessary to begin.

What you will learn

  • Make inferences from tables by joining, reshaping, and aggregating
  • Familiarize yourself with the R geospatial data analysis ecosystem
  • Prepare reproducible, publicationquality plots and maps
  • Efficiently process numeric data, characters, and dates
  • Reshape tabular data into the necessary form for the specific task at hand
  • Write R scripts to automate the handling of raster and vector spatial layers
  • Process elevation rasters and time series visualizations of satellite images
  • Perform GIS operations such as overlays and spatial queries between layers
  • Spatially interpolate meteorological data to produce climate maps

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2014
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984374
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2014
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984374
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
R Object-oriented Programming
€36.99
Learning R for Geospatial Analysis
€41.99
R for Data Science
€41.99
Total 120.97 Stars icon

Table of Contents

12 Chapters
1. The R Environment Chevron down icon Chevron up icon
2. Working with Vectors and Time Series Chevron down icon Chevron up icon
3. Working with Tables Chevron down icon Chevron up icon
4. Working with Rasters Chevron down icon Chevron up icon
5. Working with Points, Lines, and Polygons Chevron down icon Chevron up icon
6. Modifying Rasters and Analyzing Raster Time Series Chevron down icon Chevron up icon
7. Combining Vector and Raster Datasets Chevron down icon Chevron up icon
8. Spatial Interpolation of Point Data Chevron down icon Chevron up icon
9. Advanced Visualization of Spatial Data Chevron down icon Chevron up icon
A. External Datasets Used in Examples Chevron down icon Chevron up icon
B. Cited References Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(7 Ratings)
5 star 42.9%
4 star 28.6%
3 star 14.3%
2 star 0%
1 star 14.3%
Filter icon Filter
Top Reviews

Filter reviews by




R N Thornton Jan 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is clearly written and comprehensive, containing many tips about use of R in addition to its core spatial content. Code is available through the internet - essential really. I can hardly recommend this book too much for developing skills in spatial analysis.
Amazon Verified review Amazon
DARKO KRALIK Aug 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is an extraordinary introduction to geospatial analysis.At first You could get feeling that this book is so good mostly because of inate expressiveness of R.But real truth is that it's excellent selection of examples and it's methodical approach reveals R, it's geo libraries, and geospatial analysis as such in clear and simple way.And I am saying that after browsing thru dozens and dozens other geospatial books and environments.
Amazon Verified review Amazon
Alvaro Neto Oct 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very straightforward. Although I had a rudimentary understanding of R beforehand, I believe anyone with interest in the topic can pick this up.
Amazon Verified review Amazon
Kim G Mar 31, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book will likely be a great resource for new users to R who hope to perform geospatial analyses. The first three chapters of the book provide a very basic level introduction to the R language and environment that will be useful to new readers, but may be found extraneous and unnecessary for those familiar with using R and only seeking further information on geospatial analysis. There are small instances of when the code supplied in the text is specific to a Windows PC environment, so new users on a different operating system will be left on their own to figure this step out; though it is not a difficult step. Advanced R users may also find the repeated instances throughout the chapters of how to load and look at your data to be tedious. Though I have not assessed this book in its entirety, I found the discussion on working with layers of data very useful to tasks I have tried implementing in the past. The book does a good job of describing many of the existing mapping tools that R is capable of, and should be useful to future researchers and data scientists.
Amazon Verified review Amazon
Christian S. Mar 19, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is a great intro for geospatial analysis. The book is self contained and gives you a brief practical intro to R. The first three chapters give you the basics of the data structures and libraries you need to understand to follow the remaining chapters of the book.In chapter 4 is where the fun part starts. The intro to each chapter is clear and concise and the examples are nice to work with. The visualizations are great.The ebook has the images in full color, not sure about the printed version.Even though the author uses Windows file paths in their examples, it was easy to adjust them to work on a Mac using RStudio. The book provides a complete set of images and raster files as part of the source code.I wish the author had included examples of least-cost paths. It was just mentioned briefly.In summary I would recommend this book as a great intro to R and geospatial analysis and visualization.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.