WEBVTT

00:00:00.000 --> 00:00:02.425 align:middle line:84%
[SQUEAKING]
[RUSTLING] [CLICKING]

00:00:02.425 --> 00:00:08.635 align:middle line:90%


00:00:08.635 --> 00:00:10.510 align:middle line:84%
HELENA VAILLICROSA: In
this part of the code,

00:00:10.510 --> 00:00:14.260 align:middle line:84%
I'm going to guide you through
the gap-filling process based

00:00:14.260 --> 00:00:15.470 align:middle line:90%
on maps.

00:00:15.470 --> 00:00:19.970 align:middle line:84%
So this is a process that I
use quite a lot in my research,

00:00:19.970 --> 00:00:23.470 align:middle line:84%
which is when I'm facing
a new database sometimes

00:00:23.470 --> 00:00:27.850 align:middle line:84%
comes with some empty slots,
some N/As in the data.

00:00:27.850 --> 00:00:32.680 align:middle line:84%
And I want to fill them
based on field data.

00:00:32.680 --> 00:00:36.970 align:middle line:84%
Obviously, data coming
from maps is not

00:00:36.970 --> 00:00:40.340 align:middle line:84%
as accurate as data coming
from field experiments.

00:00:40.340 --> 00:00:44.260 align:middle line:84%
But this is a good proxy we have
to maximize the data we have

00:00:44.260 --> 00:00:47.840 align:middle line:90%
and use them all in our models.

00:00:47.840 --> 00:00:49.960 align:middle line:84%
So what I'm going
to be doing here

00:00:49.960 --> 00:00:53.440 align:middle line:84%
is to use the latitude and
longitude of the coordinates

00:00:53.440 --> 00:00:57.190 align:middle line:84%
that comes into the
databases, transform them

00:00:57.190 --> 00:00:59.740 align:middle line:84%
into spatial-explicit
data points,

00:00:59.740 --> 00:01:02.950 align:middle line:84%
and use these data
points to extract

00:01:02.950 --> 00:01:07.190 align:middle line:90%
the data coming from a map.

00:01:07.190 --> 00:01:08.380 align:middle line:90%
So let's just go ahead.

00:01:08.380 --> 00:01:11.600 align:middle line:84%
I'm going to download
real data that I created

00:01:11.600 --> 00:01:13.310 align:middle line:90%
that is in my GitHub account.

00:01:13.310 --> 00:01:15.980 align:middle line:90%
You can download it freely here.

00:01:15.980 --> 00:01:19.760 align:middle line:84%
It's a database that calculates
nitrogen uptake global scale

00:01:19.760 --> 00:01:22.790 align:middle line:90%
based on field data.

00:01:22.790 --> 00:01:25.670 align:middle line:84%
But I encountered that
some of the drivers--

00:01:25.670 --> 00:01:28.190 align:middle line:84%
temperature, precipitation,
soil information--

00:01:28.190 --> 00:01:30.770 align:middle line:84%
has not always been
collected, or maybe

00:01:30.770 --> 00:01:34.080 align:middle line:84%
wasn't reported in
the original papers.

00:01:34.080 --> 00:01:38.370 align:middle line:84%
So that's why there
are some data gaps.

00:01:38.370 --> 00:01:42.980 align:middle line:84%
So well, you can see that
it's is a big database.

00:01:42.980 --> 00:01:44.640 align:middle line:90%
It includes a lot of columns.

00:01:44.640 --> 00:01:46.280 align:middle line:90%
Some of them are complete.

00:01:46.280 --> 00:01:47.510 align:middle line:90%
Some of them have N/As.

00:01:47.510 --> 00:01:51.180 align:middle line:90%


00:01:51.180 --> 00:01:56.330 align:middle line:84%
So I'm just going to
see how are they called.

00:01:56.330 --> 00:01:58.710 align:middle line:84%
These are all the
names of the columns.

00:01:58.710 --> 00:02:00.410 align:middle line:84%
And we are going
to be particularly

00:02:00.410 --> 00:02:02.570 align:middle line:84%
interested in the latitude
and longitude, which

00:02:02.570 --> 00:02:04.550 align:middle line:84%
is the third and fourth
column right here.

00:02:04.550 --> 00:02:08.020 align:middle line:90%


00:02:08.020 --> 00:02:11.640 align:middle line:84%
I'm going to make sure that
we don't have N/As there.

00:02:11.640 --> 00:02:15.920 align:middle line:84%
So I'm just going to subset the
data that doesn't include N/As.

00:02:15.920 --> 00:02:22.220 align:middle line:84%
So it is N/A. So it doesn't
include N/A in the latitude.

00:02:22.220 --> 00:02:25.200 align:middle line:84%
And it doesn't include
N/As the longitude.

00:02:25.200 --> 00:02:27.320 align:middle line:84%
This is one of the
several ways we

00:02:27.320 --> 00:02:29.930 align:middle line:84%
have to make sure
that we exclude N/As

00:02:29.930 --> 00:02:33.740 align:middle line:90%
in these particular columns.

00:02:33.740 --> 00:02:34.460 align:middle line:90%
OK.

00:02:34.460 --> 00:02:36.320 align:middle line:84%
Now that we have
this sorted out,

00:02:36.320 --> 00:02:39.900 align:middle line:84%
there are two ways of
transforming these data points,

00:02:39.900 --> 00:02:43.290 align:middle line:84%
so this latitude and longitude
in data-explicit points.

00:02:43.290 --> 00:02:45.350 align:middle line:90%
One is using SpatialPoints here.

00:02:45.350 --> 00:02:49.250 align:middle line:84%
And the other one is using
SpatialPointsDataFrame.

00:02:49.250 --> 00:02:51.800 align:middle line:84%
In both of them,
I need to specify

00:02:51.800 --> 00:02:55.490 align:middle line:84%
where latitude and longitude
are located, what's

00:02:55.490 --> 00:02:57.150 align:middle line:90%
the database that I'm using.

00:02:57.150 --> 00:03:01.100 align:middle line:84%
And in the first case, I need
to specify also the resolution

00:03:01.100 --> 00:03:02.720 align:middle line:90%
I want the data to be.

00:03:02.720 --> 00:03:04.640 align:middle line:90%
I personally like this more.

00:03:04.640 --> 00:03:06.290 align:middle line:84%
But with this one
right here, it's

00:03:06.290 --> 00:03:10.720 align:middle line:84%
going to also work for
our purposes right now.

00:03:10.720 --> 00:03:15.760 align:middle line:84%
We see that the outcome we get
is a slightly different one

00:03:15.760 --> 00:03:21.630 align:middle line:84%
in SpatialPointsDataFrame and
the other one is SpatialPoints.

00:03:21.630 --> 00:03:25.310 align:middle line:84%
But if we plot them
they look very similar.

00:03:25.310 --> 00:03:30.760 align:middle line:90%


00:03:30.760 --> 00:03:37.195 align:middle line:84%
And we can plot them with
the shape of the Earth.

00:03:37.195 --> 00:03:38.920 align:middle line:84%
We don't have a
good understanding

00:03:38.920 --> 00:03:40.855 align:middle line:90%
of what is this plotting.

00:03:40.855 --> 00:03:44.200 align:middle line:90%


00:03:44.200 --> 00:03:47.410 align:middle line:84%
Here, I added this map
that we already used

00:03:47.410 --> 00:03:51.620 align:middle line:90%
in other parts of the videos.

00:03:51.620 --> 00:03:54.940 align:middle line:84%
So here, we can have a
good understanding of where

00:03:54.940 --> 00:03:57.490 align:middle line:90%
this data is coming from.

00:03:57.490 --> 00:03:59.380 align:middle line:84%
And it also certifies
that we have

00:03:59.380 --> 00:04:01.520 align:middle line:90%
built our map appropriately.

00:04:01.520 --> 00:04:04.310 align:middle line:84%
Sometimes, if you mismatch
latitude and longitude,

00:04:04.310 --> 00:04:09.020 align:middle line:84%
you're going to
have a twisted map.

00:04:09.020 --> 00:04:11.710 align:middle line:90%
So let's just try it for fun.

00:04:11.710 --> 00:04:25.003 align:middle line:90%


00:04:25.003 --> 00:04:26.170 align:middle line:90%
Let's see how it looks like.

00:04:26.170 --> 00:04:29.220 align:middle line:90%


00:04:29.220 --> 00:04:34.080 align:middle line:84%
You see, now, it's totally
changed 90 degrees.

00:04:34.080 --> 00:04:37.230 align:middle line:84%
But just a heads up to
put latitude and longitude

00:04:37.230 --> 00:04:42.720 align:middle line:90%
in the appropriate location.

00:04:42.720 --> 00:04:43.830 align:middle line:90%
OK.

00:04:43.830 --> 00:04:48.120 align:middle line:84%
So going back to
the process, I'm

00:04:48.120 --> 00:04:51.060 align:middle line:84%
going to use as a base
this map that we've

00:04:51.060 --> 00:04:54.660 align:middle line:84%
been using recurrently, which
is this temperature map.

00:04:54.660 --> 00:04:58.990 align:middle line:84%
And I want to extract the
information using these points.

00:04:58.990 --> 00:05:02.220 align:middle line:84%
So I only need to use the
function extract, the map where

00:05:02.220 --> 00:05:03.750 align:middle line:84%
I want to take the
information, from

00:05:03.750 --> 00:05:07.930 align:middle line:84%
and the points I want to
use to extract the data.

00:05:07.930 --> 00:05:09.240 align:middle line:90%
So I use these.

00:05:09.240 --> 00:05:17.550 align:middle line:84%
And I see that the result is
this right here-- oh, sorry--

00:05:17.550 --> 00:05:21.020 align:middle line:90%


00:05:21.020 --> 00:05:21.590 align:middle line:90%
here.

00:05:21.590 --> 00:05:24.990 align:middle line:84%
And we see that we
have a new value here,

00:05:24.990 --> 00:05:31.280 align:middle line:84%
a new vector that is 159 data
points long, which is exactly

00:05:31.280 --> 00:05:33.140 align:middle line:90%
the same number of columns--

00:05:33.140 --> 00:05:36.530 align:middle line:84%
of rows, sorry, we
have in our data frame.

00:05:36.530 --> 00:05:40.670 align:middle line:84%
And if instead of
having one map here

00:05:40.670 --> 00:05:44.570 align:middle line:84%
we would have had
a stack or a brick,

00:05:44.570 --> 00:05:47.880 align:middle line:84%
we would have had
a column per map.

00:05:47.880 --> 00:05:51.350 align:middle line:84%
So in this case, we only have
one because we have one map.

00:05:51.350 --> 00:05:53.480 align:middle line:84%
But the more maps we
have, the more columns

00:05:53.480 --> 00:05:59.660 align:middle line:90%
it would add in our result.

00:05:59.660 --> 00:06:02.660 align:middle line:84%
Now, I'm going to guide you
through an exercise that

00:06:02.660 --> 00:06:05.990 align:middle line:84%
hopefully is going to
be a good summary of all

00:06:05.990 --> 00:06:07.640 align:middle line:84%
the functions and
all the concepts

00:06:07.640 --> 00:06:14.510 align:middle line:84%
we've been working with
in this GIS session.

00:06:14.510 --> 00:06:15.990 align:middle line:84%
I'm going to guide
you through it.

00:06:15.990 --> 00:06:18.150 align:middle line:84%
So initially, there's
nothing done here.

00:06:18.150 --> 00:06:23.090 align:middle line:84%
So I'm going to type
while doing it live.

00:06:23.090 --> 00:06:26.240 align:middle line:84%
And first of all,
I would ask you

00:06:26.240 --> 00:06:29.330 align:middle line:84%
to download these 10-meter
resolution average temperature

00:06:29.330 --> 00:06:31.550 align:middle line:90%
maps from WorldClim.

00:06:31.550 --> 00:06:32.930 align:middle line:90%
And this is the link.

00:06:32.930 --> 00:06:34.820 align:middle line:84%
But in case you
don't have it handy,

00:06:34.820 --> 00:06:37.760 align:middle line:84%
this is how the web
page looks like.

00:06:37.760 --> 00:06:40.370 align:middle line:84%
I would ask you to go to
this average temperature

00:06:40.370 --> 00:06:42.470 align:middle line:90%
and download this one.

00:06:42.470 --> 00:06:45.050 align:middle line:84%
Feel free to download
other resolutions as well.

00:06:45.050 --> 00:06:47.270 align:middle line:84%
But I just went
to the course one

00:06:47.270 --> 00:06:51.170 align:middle line:84%
to make the explanation more
fluid and the calculations

00:06:51.170 --> 00:06:55.410 align:middle line:90%
easier to calculate.

00:06:55.410 --> 00:06:57.590 align:middle line:84%
So let's download
these and store it

00:06:57.590 --> 00:07:01.020 align:middle line:84%
somewhere in your computer
that you know the oute of.

00:07:01.020 --> 00:07:05.640 align:middle line:84%
And also, I'm going to ask you
to load all these maps in your R

00:07:05.640 --> 00:07:08.970 align:middle line:84%
session and calculate the
average of all the maps,

00:07:08.970 --> 00:07:13.020 align:middle line:84%
so to obtain the yearly
average temperature.

00:07:13.020 --> 00:07:13.680 align:middle line:90%
OK.

00:07:13.680 --> 00:07:16.440 align:middle line:84%
To do that, I'm going to use
code that we've already used.

00:07:16.440 --> 00:07:19.950 align:middle line:90%
I'm just going to jump around.

00:07:19.950 --> 00:07:22.200 align:middle line:90%
I think I have this code here.

00:07:22.200 --> 00:07:24.240 align:middle line:90%
Yes.

00:07:24.240 --> 00:07:25.185 align:middle line:90%
I'm going to use this.

00:07:25.185 --> 00:07:34.160 align:middle line:90%


00:07:34.160 --> 00:07:36.350 align:middle line:84%
So I'm going to charge
everything at once,

00:07:36.350 --> 00:07:38.110 align:middle line:90%
instead of going one by one.

00:07:38.110 --> 00:07:40.450 align:middle line:90%
I'm going to do it faster.

00:07:40.450 --> 00:07:42.790 align:middle line:90%
This and this--

00:07:42.790 --> 00:07:45.700 align:middle line:84%
I don't really want
this code here.

00:07:45.700 --> 00:07:48.840 align:middle line:90%


00:07:48.840 --> 00:07:51.990 align:middle line:84%
I'm going to create
a stack of these.

00:07:51.990 --> 00:07:56.190 align:middle line:84%
And now, we want to calculate
the mean of all these maps.

00:07:56.190 --> 00:07:59.145 align:middle line:84%
So to do that, it's
going to be called--

00:07:59.145 --> 00:08:06.740 align:middle line:90%


00:08:06.740 --> 00:08:16.305 align:middle line:84%
I'm going to use this object
here and calculate the mean.

00:08:16.305 --> 00:08:19.770 align:middle line:90%


00:08:19.770 --> 00:08:20.610 align:middle line:90%
This is what we got.

00:08:20.610 --> 00:08:23.180 align:middle line:90%


00:08:23.180 --> 00:08:25.940 align:middle line:84%
So see that the
information looks good.

00:08:25.940 --> 00:08:28.210 align:middle line:84%
The values-- minimum,
the maximum--

00:08:28.210 --> 00:08:29.720 align:middle line:90%
they look feasible.

00:08:29.720 --> 00:08:33.340 align:middle line:84%
So it seems that everything
worked out pretty well.

00:08:33.340 --> 00:08:35.860 align:middle line:84%
I'm just going to plot it
to see how it looks like.

00:08:35.860 --> 00:08:43.510 align:middle line:90%


00:08:43.510 --> 00:08:44.800 align:middle line:90%
So yeah, it seems reasonable.

00:08:44.800 --> 00:08:48.790 align:middle line:84%
So I think we've successfully
completed the first step.

00:08:48.790 --> 00:08:54.030 align:middle line:84%
Second step-- I want you to
download the nitrogen uptake

00:08:54.030 --> 00:08:58.230 align:middle line:84%
data from this page,
which is my GitHub page.

00:08:58.230 --> 00:09:01.000 align:middle line:84%
This is the database we've
used in the previous exercise.

00:09:01.000 --> 00:09:02.790 align:middle line:90%
So you might have it already.

00:09:02.790 --> 00:09:05.520 align:middle line:84%
And I'm going to ask you
to create a new dataframe

00:09:05.520 --> 00:09:10.200 align:middle line:84%
by subsetting the columns
numbered 3, 4, and 18, which

00:09:10.200 --> 00:09:13.950 align:middle line:84%
are the latitude, longitude, and
mean annual temperature, which

00:09:13.950 --> 00:09:18.670 align:middle line:84%
is what we just
calculated in our maps.

00:09:18.670 --> 00:09:25.860 align:middle line:84%
So to do that, I'm just
going to load the data

00:09:25.860 --> 00:09:27.375 align:middle line:90%
that I should have here.

00:09:27.375 --> 00:09:35.950 align:middle line:90%


00:09:35.950 --> 00:09:38.623 align:middle line:90%
This is the data.

00:09:38.623 --> 00:09:39.540 align:middle line:90%
We're going to subset.

00:09:39.540 --> 00:09:52.720 align:middle line:90%


00:09:52.720 --> 00:09:58.225 align:middle line:84%
I said the column number
3, number 4, and number 18.

00:09:58.225 --> 00:10:01.640 align:middle line:90%


00:10:01.640 --> 00:10:05.430 align:middle line:84%
Now, we have this object that
has exactly the same length--

00:10:05.430 --> 00:10:09.500 align:middle line:84%
so the same rows, but
only these three variables

00:10:09.500 --> 00:10:10.640 align:middle line:90%
that I asked you for--

00:10:10.640 --> 00:10:14.720 align:middle line:84%
latitude, longitude, and
mean annual temperature.

00:10:14.720 --> 00:10:16.670 align:middle line:84%
I chose these
variables because we

00:10:16.670 --> 00:10:19.400 align:middle line:90%
have some N/As, as I mentioned.

00:10:19.400 --> 00:10:22.220 align:middle line:84%
You see some empty
values that we would

00:10:22.220 --> 00:10:28.200 align:middle line:90%
like to fill in further steps.

00:10:28.200 --> 00:10:28.700 align:middle line:90%
OK.

00:10:28.700 --> 00:10:31.520 align:middle line:90%
Let's move on to the step 3.

00:10:31.520 --> 00:10:34.880 align:middle line:84%
I want to create spatial
points by using the coordinates

00:10:34.880 --> 00:10:37.130 align:middle line:90%
in the subsetted data frame.

00:10:37.130 --> 00:10:40.880 align:middle line:84%
And I also want to extract
the mean annual temperature

00:10:40.880 --> 00:10:44.270 align:middle line:84%
of the data points you
just created from the map

00:10:44.270 --> 00:10:48.590 align:middle line:84%
and include them in a new
vector to the data frame,

00:10:48.590 --> 00:10:51.840 align:middle line:84%
resulting in a
four-column data frame.

00:10:51.840 --> 00:11:02.280 align:middle line:84%
So I'm going to go through
the code that we just used.

00:11:02.280 --> 00:11:04.685 align:middle line:90%
Oops, sorry, sorry, sorry.

00:11:04.685 --> 00:11:18.090 align:middle line:90%


00:11:18.090 --> 00:11:19.170 align:middle line:90%
Find them here.

00:11:19.170 --> 00:11:22.930 align:middle line:90%


00:11:22.930 --> 00:11:24.593 align:middle line:90%
This one.

00:11:24.593 --> 00:11:26.385 align:middle line:84%
We're going to use this
one that's shorter.

00:11:26.385 --> 00:11:36.130 align:middle line:90%


00:11:36.130 --> 00:11:36.850 align:middle line:90%
OK.

00:11:36.850 --> 00:11:38.080 align:middle line:90%
We created that.

00:11:38.080 --> 00:11:40.580 align:middle line:84%
And now, we want to
extract this information.

00:11:40.580 --> 00:11:42.550 align:middle line:90%
So it's going to be called--

00:11:42.550 --> 00:11:50.660 align:middle line:90%


00:11:50.660 --> 00:11:55.620 align:middle line:84%
MAT stands for mean
annual temperature.

00:11:55.620 --> 00:11:59.050 align:middle line:84%
And I want to extract from
this variable that we created--

00:11:59.050 --> 00:12:00.330 align:middle line:90%
that's the mean temperature--

00:12:00.330 --> 00:12:04.980 align:middle line:90%


00:12:04.980 --> 00:12:05.980 align:middle line:90%
and the PNT.

00:12:05.980 --> 00:12:10.100 align:middle line:90%


00:12:10.100 --> 00:12:11.210 align:middle line:90%
OK.

00:12:11.210 --> 00:12:12.920 align:middle line:90%
We created this vector here.

00:12:12.920 --> 00:12:17.180 align:middle line:84%
And now, we want to add this
vector to our initial data

00:12:17.180 --> 00:12:18.710 align:middle line:90%
frame.

00:12:18.710 --> 00:12:21.230 align:middle line:90%
So our data frame was created--

00:12:21.230 --> 00:12:23.090 align:middle line:90%
was called this.

00:12:23.090 --> 00:12:27.040 align:middle line:90%


00:12:27.040 --> 00:12:32.735 align:middle line:84%
It's going to be called
Coming From WorldClim.

00:12:32.735 --> 00:12:49.000 align:middle line:90%


00:12:49.000 --> 00:12:50.355 align:middle line:90%
This is one way to do it.

00:12:50.355 --> 00:12:51.230 align:middle line:90%
There are other ways.

00:12:51.230 --> 00:12:55.660 align:middle line:84%
So if you find an easier
way that works better

00:12:55.660 --> 00:12:57.830 align:middle line:90%
for you to do it, feel free.

00:12:57.830 --> 00:13:00.550 align:middle line:84%
So now, we have this
initial database

00:13:00.550 --> 00:13:02.390 align:middle line:90%
that had only three columns.

00:13:02.390 --> 00:13:03.970 align:middle line:90%
Now, it has four columns.

00:13:03.970 --> 00:13:09.160 align:middle line:84%
And we just added this new
column here with a new variable.

00:13:09.160 --> 00:13:11.710 align:middle line:84%
We could even see
how these two match.

00:13:11.710 --> 00:13:15.380 align:middle line:84%
So this comes from
ground measurements.

00:13:15.380 --> 00:13:16.810 align:middle line:90%
So it's based on field data.

00:13:16.810 --> 00:13:17.920 align:middle line:90%
And this is the map.

00:13:17.920 --> 00:13:20.410 align:middle line:84%
We could even see
how these two match.

00:13:20.410 --> 00:13:23.650 align:middle line:84%
We could, for example,
plot these two informations

00:13:23.650 --> 00:13:25.780 align:middle line:90%
or create a linear model.

00:13:25.780 --> 00:13:27.770 align:middle line:84%
I'm just going to
go with the model.

00:13:27.770 --> 00:13:29.920 align:middle line:90%
It's going to be called Model 1.

00:13:29.920 --> 00:13:45.850 align:middle line:84%
It's going to be a linear
model, where I have these,

00:13:45.850 --> 00:13:50.500 align:middle line:90%
based on WorldClim.

00:13:50.500 --> 00:13:54.655 align:middle line:84%
This data is going
to be this one.

00:13:54.655 --> 00:14:05.010 align:middle line:90%


00:14:05.010 --> 00:14:05.590 align:middle line:90%
Let's see.

00:14:05.590 --> 00:14:07.350 align:middle line:90%
Well, it's almost the same data.

00:14:07.350 --> 00:14:10.350 align:middle line:90%
So they agree in a 94%.

00:14:10.350 --> 00:14:13.260 align:middle line:90%


00:14:13.260 --> 00:14:16.180 align:middle line:84%
Yes, almost 1, a
perfect regression.

00:14:16.180 --> 00:14:18.480 align:middle line:90%
So this is a good proxy.

00:14:18.480 --> 00:14:24.960 align:middle line:84%
We could also plot them
in a linear model--

00:14:24.960 --> 00:14:26.960 align:middle line:90%
in a regression plot.

00:14:26.960 --> 00:14:40.080 align:middle line:90%
It's just like this.

00:14:40.080 --> 00:14:44.190 align:middle line:84%
And we see how the
data mostly agrees.

00:14:44.190 --> 00:14:49.310 align:middle line:90%


00:14:49.310 --> 00:14:49.810 align:middle line:90%
OK.

00:14:49.810 --> 00:14:53.990 align:middle line:84%
And now finally, I want to
combine these two columns.

00:14:53.990 --> 00:14:56.350 align:middle line:84%
So create a new column
in your data frame

00:14:56.350 --> 00:15:00.250 align:middle line:84%
where you gap-fill the
mean annual temperature

00:15:00.250 --> 00:15:02.980 align:middle line:84%
variable with the data
you just extracted.

00:15:02.980 --> 00:15:07.420 align:middle line:84%
So what I want to
do here is to use--

00:15:07.420 --> 00:15:12.640 align:middle line:84%
so mainly use this
field experimental data,

00:15:12.640 --> 00:15:17.860 align:middle line:84%
but use the map to gap-fill
these empty spaces that I

00:15:17.860 --> 00:15:20.380 align:middle line:90%
have here.

00:15:20.380 --> 00:15:24.020 align:middle line:84%
To do so, I'm going to use
code that I already have,

00:15:24.020 --> 00:15:41.660 align:middle line:84%
which uses a for
loop, so it's faster.

00:15:41.660 --> 00:15:42.160 align:middle line:90%
OK.

00:15:42.160 --> 00:15:44.470 align:middle line:90%
What I'm doing is to--

00:15:44.470 --> 00:15:45.850 align:middle line:90%
ah, this data--

00:15:45.850 --> 00:15:53.240 align:middle line:84%
I'm going to change the
code using this tool.

00:15:53.240 --> 00:15:55.480 align:middle line:84%
So what initially
was General DB, now

00:15:55.480 --> 00:16:07.680 align:middle line:84%
it's going to be called
N in the section, which

00:16:07.680 --> 00:16:09.000 align:middle line:90%
is what I selected.

00:16:09.000 --> 00:16:11.790 align:middle line:90%
And I replace them all.

00:16:11.790 --> 00:16:14.580 align:middle line:90%
Yes, four occurrences.

00:16:14.580 --> 00:16:15.180 align:middle line:90%
OK.

00:16:15.180 --> 00:16:17.650 align:middle line:90%
And now, the data--

00:16:17.650 --> 00:16:19.920 align:middle line:84%
so what I'm going
to be doing is I'm

00:16:19.920 --> 00:16:25.860 align:middle line:84%
asking R to generate this for
loop that goes from 1 to 159,

00:16:25.860 --> 00:16:28.380 align:middle line:84%
which is the number
of rows that I have.

00:16:28.380 --> 00:16:31.650 align:middle line:90%
And I'm saying, if this is N/A--

00:16:31.650 --> 00:16:32.955 align:middle line:90%
so it's an empty space--

00:16:32.955 --> 00:16:39.070 align:middle line:90%


00:16:39.070 --> 00:16:46.030 align:middle line:84%
if this variable is an empty
space, go to the same variable

00:16:46.030 --> 00:17:03.700 align:middle line:84%
and fill this space with
what you will find here.

00:17:03.700 --> 00:17:07.470 align:middle line:84%
And if that's not an N/A,
just leave it like is.

00:17:07.470 --> 00:17:16.270 align:middle line:90%


00:17:16.270 --> 00:17:19.900 align:middle line:90%
You could even erase this part.

00:17:19.900 --> 00:17:24.069 align:middle line:84%
So we could not
need this else part

00:17:24.069 --> 00:17:26.740 align:middle line:84%
because it's basically
leaving the thing as they are.

00:17:26.740 --> 00:17:29.440 align:middle line:84%
So you could decide
to erase this.

00:17:29.440 --> 00:17:32.780 align:middle line:84%
And things would
work either way.

00:17:32.780 --> 00:17:34.240 align:middle line:90%
So I'm going to make this run.

00:17:34.240 --> 00:17:36.580 align:middle line:90%
Maybe it gives us some error.

00:17:36.580 --> 00:17:38.170 align:middle line:90%
It seemed that it went smooth.

00:17:38.170 --> 00:17:42.770 align:middle line:90%


00:17:42.770 --> 00:17:45.510 align:middle line:90%
OK.

00:17:45.510 --> 00:17:47.750 align:middle line:84%
Now, we see that
this variable here

00:17:47.750 --> 00:17:51.980 align:middle line:84%
doesn't have N/As
because we filled

00:17:51.980 --> 00:17:55.200 align:middle line:84%
these information with the
information coming here.

00:17:55.200 --> 00:17:58.010 align:middle line:84%
In this case, I have destroyed
the initial variable,

00:17:58.010 --> 00:18:00.140 align:middle line:84%
meaning that now
we no longer have

00:18:00.140 --> 00:18:02.210 align:middle line:90%
the variable with these spaces.

00:18:02.210 --> 00:18:04.700 align:middle line:84%
I could have created
a new variable, which

00:18:04.700 --> 00:18:08.540 align:middle line:84%
is what I'm going to do
now just for you to see it

00:18:08.540 --> 00:18:10.950 align:middle line:90%
and to compare things better.

00:18:10.950 --> 00:18:16.080 align:middle line:84%
So I'm going to
rerun the whole code.

00:18:16.080 --> 00:18:17.000 align:middle line:90%
A very easy way--

00:18:17.000 --> 00:18:20.930 align:middle line:90%


00:18:20.930 --> 00:18:24.770 align:middle line:84%
these are the advantages
of R, that you

00:18:24.770 --> 00:18:27.800 align:middle line:90%
can rerun things pretty easy.

00:18:27.800 --> 00:18:33.147 align:middle line:84%
And now, instead of
rearranging things

00:18:33.147 --> 00:18:34.980 align:middle line:84%
on top of the variable
that already existed,

00:18:34.980 --> 00:18:37.480 align:middle line:84%
I'm going to create a new one
that's going to be called New.

00:18:37.480 --> 00:18:42.170 align:middle line:90%


00:18:42.170 --> 00:18:46.400 align:middle line:84%
New-- I'm going to
redo the process.

00:18:46.400 --> 00:18:49.260 align:middle line:90%


00:18:49.260 --> 00:18:54.700 align:middle line:84%
Now, we have this new
code, this new column here.

00:18:54.700 --> 00:19:00.210 align:middle line:84%
And so when we have an N/A,
it's always the same as MAT.

00:19:00.210 --> 00:19:01.650 align:middle line:84%
But in the ones
that we have N/A,

00:19:01.650 --> 00:19:03.870 align:middle line:90%
we've used this one instead.

00:19:03.870 --> 00:19:10.080 align:middle line:84%
And this is a very efficient way
that we have to gap-fill data

00:19:10.080 --> 00:19:14.060 align:middle line:90%
coming from map data.

00:19:14.060 --> 00:19:19.000 align:middle line:90%