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
Mex$179.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781783984367
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 26, 2014
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984367
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 Mex$85 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 Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,262.97
R Object-oriented Programming
Mex$1004.99
Learning R for Geospatial Analysis
Mex$1128.99
R for Data Science
Mex$1128.99
Total Mex$ 3,262.97 Stars icon
Banner background image

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.