2 Non-geographic data

2.1 Cars dataset

Load the built in dataset called cars. R packages are often shipped with datasets to facilitate the exploitation of documentation.

data(cars)

It is possible to get R documentation of datasets as long as of functions:

?datasets::cars

Don’t miss the opportunity to explore the content of the table 2.1.

Table 2.1: Here is a preview of the cars data frame
speed dist
4 2
4 10
7 4
7 22
8 16
9 10
10 18
10 26
10 34
11 17

Anytime a new R object is created in the enviroment, it is advisable to explore its content. First step, get the class of the cars dataset:

class(cars)
#> [1] "data.frame"

Let’s give a look to the object size…

dim(cars)
#> [1] 50  2

…to the variables included in the cars data frame…

names(cars)
#> [1] "speed" "dist"

…and to their statistics:

summary(cars)
#>      speed           dist       
#>  Min.   : 4.0   Min.   :  2.00  
#>  1st Qu.:12.0   1st Qu.: 26.00  
#>  Median :15.0   Median : 36.00  
#>  Mean   :15.4   Mean   : 42.98  
#>  3rd Qu.:19.0   3rd Qu.: 56.00  
#>  Max.   :25.0   Max.   :120.00

See Figure 2.1.

require(stats)
require(graphics)
plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)", las = 1)
lines(lowess(cars$speed, cars$dist, f = 2/3, iter = 3), col = "red")
title(main = "cars data")
This is a figure created using the examples provided in documentation.

Figure 2.1: This is a figure created using the examples provided in documentation.

It is possible to get detailed information also on the class and data types for variables included in data frames. Indeed, compare the result for the data frame object cars

class(cars)
#> [1] "data.frame"
typeof(cars)
#> [1] "list"

…for the dist variable:

class(cars$dist)
#> [1] "numeric"
typeof(cars$dist)
#> [1] "double"

…and for the speed variable::

class(cars$speed)
#> [1] "numeric"
typeof(cars$speed)
#> [1] "double"

The same result can be obtained extracting the variable of interest first:

s = cars$speed
class(s)
#> [1] "numeric"
typeof(s)
#> [1] "double"
head(s)
#> [1] 4 4 7 7 8 9

The cars dataset offers a simple example of non-geographic information. Now let’s start the study of geographic or geospatial data.

According to the lecture on GIS & Cartography, which characteristics and variables do you expect to manage a geospatial data?