1 00:00:00,000 --> 00:00:02,766 [MUSIC PLAYING] 2 00:00:02,766 --> 00:00:05,080 3 00:00:05,080 --> 00:00:08,230 SPEAKER: Well, hello, one and all and welcome to our short on matrices 4 00:00:08,230 --> 00:00:11,980 and arrays, two structures to store data all the same 5 00:00:11,980 --> 00:00:14,230 type in multiple dimensions. 6 00:00:14,230 --> 00:00:16,280 Now, why would you do that? 7 00:00:16,280 --> 00:00:20,170 Well, I have here an aerial view of San Francisco and the Bay area 8 00:00:20,170 --> 00:00:21,078 more generally. 9 00:00:21,078 --> 00:00:22,870 And an interesting thing about this area is 10 00:00:22,870 --> 00:00:27,100 that temperatures vary between the mountains and the city and the Bay. 11 00:00:27,100 --> 00:00:31,690 We could use matrices and arrays to model how those temperatures actually 12 00:00:31,690 --> 00:00:34,180 vary in given areas. 13 00:00:34,180 --> 00:00:36,730 Now, setting aside matrices and arrays for now, 14 00:00:36,730 --> 00:00:40,420 let's just think through how we could kind of pictorialize temperatures 15 00:00:40,420 --> 00:00:42,560 across this map here. 16 00:00:42,560 --> 00:00:46,060 Well, one thing I suppose we could do is break it up into a grid 17 00:00:46,060 --> 00:00:47,830 a bit like this one here. 18 00:00:47,830 --> 00:00:52,330 Here we have a three-by-three grid with nine cells in total 19 00:00:52,330 --> 00:00:55,688 and three rows and three columns. 20 00:00:55,688 --> 00:00:57,730 Now, it turns out, I've said before, temperatures 21 00:00:57,730 --> 00:01:00,640 can vary between the city and the mountains and the Bay, 22 00:01:00,640 --> 00:01:05,209 so we could slot in temperatures to each of these cells representing 23 00:01:05,209 --> 00:01:07,400 the average temperature in the particular area 24 00:01:07,400 --> 00:01:08,520 that we're talking about. 25 00:01:08,520 --> 00:01:11,870 So for instance, in the top left here, in San Francisco, 26 00:01:11,870 --> 00:01:14,030 we could add in this temperature. 27 00:01:14,030 --> 00:01:19,040 Maybe it'll be 60 degrees Fahrenheit and keep going down this column. 28 00:01:19,040 --> 00:01:22,580 Maybe just south of that it's about 55 degrees on average, 29 00:01:22,580 --> 00:01:25,910 Fahrenheit again, and just south of that, in the mountains now, 30 00:01:25,910 --> 00:01:29,030 it's even colder, maybe 50 degrees Fahrenheit here. 31 00:01:29,030 --> 00:01:32,310 And we can keep filling things in now column by column. 32 00:01:32,310 --> 00:01:34,910 So maybe this column here has these temperatures, 33 00:01:34,910 --> 00:01:38,280 and this column here has these temperatures here. 34 00:01:38,280 --> 00:01:42,440 So each area has its own average temperature, depending, in this case, 35 00:01:42,440 --> 00:01:46,470 on where it's located in the time of day, as well. 36 00:01:46,470 --> 00:01:48,830 So what we've created here is really a matrix, 37 00:01:48,830 --> 00:01:54,870 a two-dimensional grid of values all of the same type, all numeric in this case. 38 00:01:54,870 --> 00:01:59,090 It's a 2D grid where we have, in this case, three rows and three columns, 39 00:01:59,090 --> 00:02:02,040 a three-by-three matrix, in this case. 40 00:02:02,040 --> 00:02:07,130 So let's try to build this same idea now in R, making use of a function 41 00:02:07,130 --> 00:02:08,960 that we'll call matrix. 42 00:02:08,960 --> 00:02:12,085 So we'll come over here to RStudio, and let 43 00:02:12,085 --> 00:02:19,050 me make here a file called weather.R, just like this. 44 00:02:19,050 --> 00:02:23,930 And I'll see, in my File Explorer here, I now have this file weather.R. 45 00:02:23,930 --> 00:02:27,620 We'll save temps.R data for a bit later here. 46 00:02:27,620 --> 00:02:31,040 Let me open up weather.R, and the first thing I want to do, 47 00:02:31,040 --> 00:02:36,110 is think through what data I should store in this matrix. 48 00:02:36,110 --> 00:02:39,800 Well, to do that, I'll actually first need to make a vector. 49 00:02:39,800 --> 00:02:43,700 A vector of the pieces of data I want to store in this matrix. 50 00:02:43,700 --> 00:02:48,650 So let's go back to our visualization here and see what data we have. 51 00:02:48,650 --> 00:02:50,930 Well, it turns out, when we make this matrix, 52 00:02:50,930 --> 00:02:54,480 we're going to fill it in, like we did before, column by column. 53 00:02:54,480 --> 00:02:57,050 So I want a vector that has all of these values 54 00:02:57,050 --> 00:02:59,670 that I could fill in to this matrix column by column. 55 00:02:59,670 --> 00:03:03,020 So I would start perhaps, with 60 degrees Fahrenheit, top left here. 56 00:03:03,020 --> 00:03:06,290 Then maybe 55 degrees, kind of middle left, as well, 57 00:03:06,290 --> 00:03:08,420 then 50 degrees bottom left. 58 00:03:08,420 --> 00:03:13,580 Then I would go to 60 top middle, 60 again, in the middle of the matrix here, 59 00:03:13,580 --> 00:03:17,250 and 55 down in the middle of the bottom row. 60 00:03:17,250 --> 00:03:21,710 So let's keep going here and make up our own vector to store in this matrix. 61 00:03:21,710 --> 00:03:26,570 We'll come back now to RStudio, and why don't we name this vector something 62 00:03:26,570 --> 00:03:28,650 like temps, just like this. 63 00:03:28,650 --> 00:03:33,800 And to make a vector of a certain type or to actually add in some data here, 64 00:03:33,800 --> 00:03:38,990 I can use this function called c to basically add in individual values 65 00:03:38,990 --> 00:03:40,580 to this vector. 66 00:03:40,580 --> 00:03:44,750 So the first value, as we said before, is going to be the one in the top left, 67 00:03:44,750 --> 00:03:46,340 60 degrees Fahrenheit. 68 00:03:46,340 --> 00:03:48,290 I'll make sure that I have 60 here. 69 00:03:48,290 --> 00:03:53,900 The next one, down below in the column now, was 55, followed by 50. 70 00:03:53,900 --> 00:03:56,420 And that was our first column of data. 71 00:03:56,420 --> 00:03:57,710 Let's move to the next column. 72 00:03:57,710 --> 00:04:05,060 I believe that one began with 60 here, then we had 60 again, and then 55. 73 00:04:05,060 --> 00:04:08,953 Let's check that 60, 60, and 55. 74 00:04:08,953 --> 00:04:09,620 OK, pretty good. 75 00:04:09,620 --> 00:04:11,210 Let's do the next column now. 76 00:04:11,210 --> 00:04:15,472 I'll say that one was 65, 60, and 60. 77 00:04:15,472 --> 00:04:16,430 Let's check that again. 78 00:04:16,430 --> 00:04:19,399 I see 65, 60, and 60. 79 00:04:19,399 --> 00:04:21,529 So it seems like our vector is appropriate now 80 00:04:21,529 --> 00:04:23,660 for building this matrix. 81 00:04:23,660 --> 00:04:26,660 Let's come back now here, and we want to make sure we actually 82 00:04:26,660 --> 00:04:29,090 store this vector temps. 83 00:04:29,090 --> 00:04:32,150 And if I type now temps in my console, I should, hopefully, 84 00:04:32,150 --> 00:04:35,750 see all these numbers that are part of my vector. 85 00:04:35,750 --> 00:04:39,860 Now, to make this matrix, I actually use a function called matrix. 86 00:04:39,860 --> 00:04:42,120 And I would use it a bit like this. 87 00:04:42,120 --> 00:04:47,910 I could use matrix by typing in the matrix function, just like this. 88 00:04:47,910 --> 00:04:51,350 And it turns out that matrix takes a few arguments. 89 00:04:51,350 --> 00:04:54,890 One is this vector called temps, the very first one. 90 00:04:54,890 --> 00:04:58,310 The data we want to actually store inside of this matrix. 91 00:04:58,310 --> 00:05:00,920 So I'll type temps here, saying that I will 92 00:05:00,920 --> 00:05:06,580 use this vector I defined earlier to fill in this matrix I'm about to create. 93 00:05:06,580 --> 00:05:11,950 Now the next two arguments, they are defined by the number of rows 94 00:05:11,950 --> 00:05:15,220 and the number of columns we actually want to have in this matrix. 95 00:05:15,220 --> 00:05:17,710 So again, we had a three-by-three matrix, 96 00:05:17,710 --> 00:05:20,590 meaning we had three rows and three columns. 97 00:05:20,590 --> 00:05:23,500 And then when we specify this in R is as follows, 98 00:05:23,500 --> 00:05:29,230 I can say n row, for number of rows, and set it equal to some value, like 3, 99 00:05:29,230 --> 00:05:30,590 in this case. 100 00:05:30,590 --> 00:05:36,710 I could also do ncol, another argument here, and set that equal to 3, as well. 101 00:05:36,710 --> 00:05:40,180 So now I've said, take this data from my temps vector 102 00:05:40,180 --> 00:05:44,450 and turn it into a matrix that has three rows and three columns. 103 00:05:44,450 --> 00:05:47,890 So if I'm at my console, a little bit bigger down here, 104 00:05:47,890 --> 00:05:51,910 and I were to run this function matrix here, what should I see? 105 00:05:51,910 --> 00:05:55,750 Well, a matrix down below looking very similar to the grid 106 00:05:55,750 --> 00:05:58,780 we saw in our slides, albeit without the background here. 107 00:05:58,780 --> 00:06:05,660 I see the first column of 60, 55, and 50 next column 60, 60, 55, 108 00:06:05,660 --> 00:06:08,720 and then 65, 60, and 60 again. 109 00:06:08,720 --> 00:06:11,690 So why don't we store this now in its own object. 110 00:06:11,690 --> 00:06:13,520 I'll call this one weather. 111 00:06:13,520 --> 00:06:16,590 And I'll assign it now to this name. 112 00:06:16,590 --> 00:06:20,750 So if I type weather, in the future, I should now see this matrix of values, 113 00:06:20,750 --> 00:06:24,860 a three-by-three grid of these values all of the same type. 114 00:06:24,860 --> 00:06:27,890 Now, matrices can be of any dimension, actually, really 115 00:06:27,890 --> 00:06:29,870 of any number of rows or columns. 116 00:06:29,870 --> 00:06:31,820 They have to be two dimensional, that is. 117 00:06:31,820 --> 00:06:35,960 Now, I can make this four columns or four rows, 118 00:06:35,960 --> 00:06:39,350 whatever it is, as long as my vector has enough data to fill 119 00:06:39,350 --> 00:06:42,630 in all of those rows and columns. 120 00:06:42,630 --> 00:06:45,620 So if we have this matrix, what can we do with it? 121 00:06:45,620 --> 00:06:48,600 One thing we can do is try to access certain values. 122 00:06:48,600 --> 00:06:52,790 So if I tried here to maybe store this as a matrix, as I've already done, 123 00:06:52,790 --> 00:06:57,890 I could then ask the question, what does this first row of values look like? 124 00:06:57,890 --> 00:07:01,520 I could access that first row of values by using a syntax, actually, 125 00:07:01,520 --> 00:07:02,900 just like we saw down below. 126 00:07:02,900 --> 00:07:08,510 If I look down below here, I'll see that the first row seems to have this syntax 127 00:07:08,510 --> 00:07:09,665 in front of it, [1,_]. 128 00:07:09,665 --> 00:07:12,260 129 00:07:12,260 --> 00:07:16,880 Hmm, so if I actually go to my program here and type weather, 130 00:07:16,880 --> 00:07:23,000 the name of our, in this case, matrix, and then I type [1,_] space 131 00:07:23,000 --> 00:07:26,420 for style's sake, I'll hit Enter here, command Enter, 132 00:07:26,420 --> 00:07:31,130 and I'll actually see the very first row of values in our matrix. 133 00:07:31,130 --> 00:07:32,270 Let's check that again. 134 00:07:32,270 --> 00:07:37,940 Here, I'll go back, and I see 60, 60, and 65 for the first row of this matrix, 135 00:07:37,940 --> 00:07:39,420 so pretty good. 136 00:07:39,420 --> 00:07:42,840 I could even try to find values by column, too. 137 00:07:42,840 --> 00:07:47,060 So I could use weather, and then I could leave the first part blank, 138 00:07:47,060 --> 00:07:52,200 just do comma space, and then type in 1, and that would give me, in this case, 139 00:07:52,200 --> 00:07:54,360 the first column of values. 140 00:07:54,360 --> 00:07:56,880 So to be clear, what we're doing here is this. 141 00:07:56,880 --> 00:08:03,020 When I did weather [1,_], I was asking for this first row of values, 142 00:08:03,020 --> 00:08:07,250 and when I did the second thing I did here, weather [, 1], 143 00:08:07,250 --> 00:08:10,680 I'm asking for the first column of values in this matrix. 144 00:08:10,680 --> 00:08:14,450 And I could use 1, 2, or 3 the indexes for this matrix 145 00:08:14,450 --> 00:08:18,140 here, to get any row or any column I would like. 146 00:08:18,140 --> 00:08:19,700 Now, I can also combine these. 147 00:08:19,700 --> 00:08:26,415 So let's say I were to type this, weather [1,1], 148 00:08:26,415 --> 00:08:29,540 I'm curious what you think that would give me if we look back at our matrix 149 00:08:29,540 --> 00:08:30,560 here. 150 00:08:30,560 --> 00:08:34,520 Might give us, in this case, the value in the first row 151 00:08:34,520 --> 00:08:38,570 and in the first column, which would be this top left one 60 degrees. 152 00:08:38,570 --> 00:08:39,559 So let's try that. 153 00:08:39,559 --> 00:08:43,730 If I type this and run this line of code here on line 11, 154 00:08:43,730 --> 00:08:48,980 I should see I get back 60 degrees from this matrix of values I've created. 155 00:08:48,980 --> 00:08:50,660 So pretty handy here. 156 00:08:50,660 --> 00:08:53,490 And there are other options for making matrices, too. 157 00:08:53,490 --> 00:08:57,920 So if I were to type, ?matrix to actually open up the documentation 158 00:08:57,920 --> 00:09:02,810 for matrices, I would see exactly how I could use this matrix function and some 159 00:09:02,810 --> 00:09:04,980 other parameters inside of it. 160 00:09:04,980 --> 00:09:07,970 So let me go over here and show you what that could look like. 161 00:09:07,970 --> 00:09:12,260 If I scroll down, and look at the usage now for matrix, 162 00:09:12,260 --> 00:09:15,350 I'll see that, again, the first argument was-- 163 00:09:15,350 --> 00:09:18,200 the one we gave it --in this case, it has a name, "data," 164 00:09:18,200 --> 00:09:21,830 but we gave the value of temps for our vector now. 165 00:09:21,830 --> 00:09:26,870 We set these parameters here, nrow and ncol, which are by default 1. 166 00:09:26,870 --> 00:09:31,350 And we could also change this parameter here called byrow. 167 00:09:31,350 --> 00:09:37,318 So by default, we filled in our matrix by column first, first the first column, 168 00:09:37,318 --> 00:09:39,110 then the next column, and the third column, 169 00:09:39,110 --> 00:09:44,340 but we could invert that, and instead, fill in our data by row instead. 170 00:09:44,340 --> 00:09:46,160 And there's one more here down here, too, 171 00:09:46,160 --> 00:09:51,200 one called dimnames, which let us name the dimensions of our matrix. 172 00:09:51,200 --> 00:09:53,360 The one going top to bottom, and the one going 173 00:09:53,360 --> 00:09:57,080 left to right, in this case, kind of our x- or y-axis, if you will, 174 00:09:57,080 --> 00:09:59,240 inside of our matrix. 175 00:09:59,240 --> 00:10:04,660 So this is how we can make matrices in R and access their values. 176 00:10:04,660 --> 00:10:08,530 Now, there is a more advanced data structure that 177 00:10:08,530 --> 00:10:10,630 might actually come in handy for us. 178 00:10:10,630 --> 00:10:12,470 One called an array. 179 00:10:12,470 --> 00:10:14,480 So let's look at why we might use an array 180 00:10:14,480 --> 00:10:18,560 and think through, conceptually, what it could represent for us in this case. 181 00:10:18,560 --> 00:10:22,300 So I'll come back now to our slides, and let's think. 182 00:10:22,300 --> 00:10:26,650 So this represents temperatures at a certain moment in time, 183 00:10:26,650 --> 00:10:30,610 maybe in the afternoon time, but as evening approaches, 184 00:10:30,610 --> 00:10:32,950 these temperatures might actually change. 185 00:10:32,950 --> 00:10:36,730 They might go from this to this, getting a little bit colder 186 00:10:36,730 --> 00:10:38,290 as the night goes on. 187 00:10:38,290 --> 00:10:42,290 And maybe around midnight or so, once it is definitively night time, 188 00:10:42,290 --> 00:10:43,570 it might be even colder. 189 00:10:43,570 --> 00:10:47,030 Maybe it changes to be a temperature landscape more like this here. 190 00:10:47,030 --> 00:10:49,330 So temperatures can change over time. 191 00:10:49,330 --> 00:10:53,500 Each location can have its own temperature change over time. 192 00:10:53,500 --> 00:10:57,370 Now, to represent this, you might notice we're using multiple matrices. 193 00:10:57,370 --> 00:11:02,170 If I go back to our very first one, this was one matrix, this was another matrix, 194 00:11:02,170 --> 00:11:04,520 and this was a third matrix. 195 00:11:04,520 --> 00:11:08,030 So how could we combine these into one data structure? 196 00:11:08,030 --> 00:11:11,540 Well, we can do so by thinking in three dimensions. 197 00:11:11,540 --> 00:11:15,620 So here we have a cube, a good visual metaphor for what we're about to do. 198 00:11:15,620 --> 00:11:19,520 You can imagine, again, our first matrix, which was two dimensional, 199 00:11:19,520 --> 00:11:21,990 had three rows and three columns. 200 00:11:21,990 --> 00:11:25,820 But you could also visualize time on its own axis 201 00:11:25,820 --> 00:11:28,820 here, this third dimension that stretches back, in this case, 202 00:11:28,820 --> 00:11:29,910 for instance. 203 00:11:29,910 --> 00:11:32,750 You could imagine that these temperatures change 204 00:11:32,750 --> 00:11:35,060 over time in this third dimension. 205 00:11:35,060 --> 00:11:37,100 So for instance, if we look at, let's say, 206 00:11:37,100 --> 00:11:40,520 the top-right cell in each of our matrices, 207 00:11:40,520 --> 00:11:45,500 notice how it is first 65 degrees Fahrenheit, then as evening comes, 208 00:11:45,500 --> 00:11:48,650 it stays about 65 degrees, but then as night time comes, 209 00:11:48,650 --> 00:11:50,900 it changes to 55 degrees. 210 00:11:50,900 --> 00:11:53,930 So time, in this case, is a third dimension stretching 211 00:11:53,930 --> 00:11:56,630 backwards from our point of view now. 212 00:11:56,630 --> 00:11:59,870 So you can have these structures that are multi-dimensional, 213 00:11:59,870 --> 00:12:04,070 not just 2D but 3D or 4D, 5D, however many dimensions you want, 214 00:12:04,070 --> 00:12:06,360 you can make in terms of an array. 215 00:12:06,360 --> 00:12:09,440 So let's go ahead and try this out using this same data. 216 00:12:09,440 --> 00:12:14,330 We'll come back now to weather.R. And let me clear what I have right now 217 00:12:14,330 --> 00:12:19,760 and instead, load in this new vector I created and stored inside of this file 218 00:12:19,760 --> 00:12:23,760 called temps.RData, on the right-hand side here. 219 00:12:23,760 --> 00:12:28,820 So if I were to run this, load("temps.RData"), 220 00:12:28,820 --> 00:12:32,060 saying take whatever data is stored inside this file, 221 00:12:32,060 --> 00:12:35,060 temps.RData and load it into my environment, well, 222 00:12:35,060 --> 00:12:40,730 I should get now a new value for this vector temps. 223 00:12:40,730 --> 00:12:46,460 If I hit command Enter here, you'll see a lot more values in this vector. 224 00:12:46,460 --> 00:12:49,490 And this is because we have enough data to fill in, 225 00:12:49,490 --> 00:12:52,520 not just that first matrix, not just that second, 226 00:12:52,520 --> 00:12:54,770 but also that third matrix, too. 227 00:12:54,770 --> 00:12:59,690 Enough values to fill in three whole three-by-three matrices stretching back 228 00:12:59,690 --> 00:13:01,580 in time, if you will. 229 00:13:01,580 --> 00:13:03,950 So how can we turn this vector into an array? 230 00:13:03,950 --> 00:13:07,080 Well, we can use, in this case, the array function. 231 00:13:07,080 --> 00:13:09,020 So I will do just that here. 232 00:13:09,020 --> 00:13:12,290 It looks very similar to our matrix function in terms of usage. 233 00:13:12,290 --> 00:13:16,910 I could type array, just like this, and I could give in, as the first argument 234 00:13:16,910 --> 00:13:19,040 here, this temps vector. 235 00:13:19,040 --> 00:13:23,960 So I'll say temps is the vector we'll use to fill in this array of values. 236 00:13:23,960 --> 00:13:26,390 But then array differs slightly from matrix, 237 00:13:26,390 --> 00:13:31,610 and it takes another argument, another parameter one called dim, dim. 238 00:13:31,610 --> 00:13:33,860 And dim stands for dimensions. 239 00:13:33,860 --> 00:13:38,940 Now, the dimension argument actually takes a vector as input itself. 240 00:13:38,940 --> 00:13:41,870 So here I'll define a new vector using our c function. 241 00:13:41,870 --> 00:13:45,890 And I could say, well, what kind of dimensions do I want? 242 00:13:45,890 --> 00:13:51,560 We saw before, when we had a 2D matrix, it was a three-by-three matrix, 243 00:13:51,560 --> 00:13:55,520 but now if I look back at our cube, you might notice that, well, 244 00:13:55,520 --> 00:13:57,440 there are three matrices here. 245 00:13:57,440 --> 00:14:02,930 It's kind of like we have a three by three by three structure three rows, 246 00:14:02,930 --> 00:14:06,950 three columns, but each of those stretches back three different times. 247 00:14:06,950 --> 00:14:10,220 And you can visualize it a bit more like this notice how we have, 248 00:14:10,220 --> 00:14:14,240 again three rows, three columns, but three of those rows 249 00:14:14,240 --> 00:14:16,880 and columns stretching back in time. 250 00:14:16,880 --> 00:14:18,890 So let's look at this now. 251 00:14:18,890 --> 00:14:23,180 I could actually represent this same cube by making a vector like this, 252 00:14:23,180 --> 00:14:26,150 3,3,3. 253 00:14:26,150 --> 00:14:30,620 And this specifies I want three rows, three columns, and each of those 254 00:14:30,620 --> 00:14:34,040 is stretched back three times in this other dimension we have. 255 00:14:34,040 --> 00:14:37,520 So if I were to run this line of code here on line five, 256 00:14:37,520 --> 00:14:41,360 you could then see a much more complex output down below. 257 00:14:41,360 --> 00:14:43,520 But we can break it down into smaller pieces. 258 00:14:43,520 --> 00:14:46,640 Notice here, that this should look a little bit familiar. 259 00:14:46,640 --> 00:14:50,360 This is the matrix we had at the beginning of our temperatures at one 260 00:14:50,360 --> 00:14:51,860 point in time. 261 00:14:51,860 --> 00:14:56,030 But then, we also have the next matrix down below here, 262 00:14:56,030 --> 00:14:58,910 and the next matrix down below here representing 263 00:14:58,910 --> 00:15:02,640 how the temperatures have changed over time, as well. 264 00:15:02,640 --> 00:15:07,425 So how could we access this data in this three-dimensional structure? 265 00:15:07,425 --> 00:15:10,920 Well, we could actually still make use of this comma syntax. 266 00:15:10,920 --> 00:15:12,060 We see a hint here. 267 00:15:12,060 --> 00:15:17,670 Notice how I have comma comma 1, this seems to give me this matrix. 268 00:15:17,670 --> 00:15:22,290 Comma comma 2, well, this gives me this matrix, our second one here, 269 00:15:22,290 --> 00:15:26,380 and comma comma 3, gives me our third matrix here. 270 00:15:26,380 --> 00:15:27,900 So I actually could try this. 271 00:15:27,900 --> 00:15:31,680 If I go into our file, I could store this now 272 00:15:31,680 --> 00:15:35,280 as the new array for this weather object. 273 00:15:35,280 --> 00:15:37,290 I'll hit command Enter to store that. 274 00:15:37,290 --> 00:15:44,610 And now, if I were to type, on line 10, weather[,, 1], 275 00:15:44,610 --> 00:15:46,560 what do you think I should see? 276 00:15:46,560 --> 00:15:49,740 Probably the first matrix in this 3D structure. 277 00:15:49,740 --> 00:15:53,520 So I'll hit Enter now, and I'll actually get back that very first matrix 278 00:15:53,520 --> 00:15:54,522 from before. 279 00:15:54,522 --> 00:15:56,730 But then how did these temperatures change over time? 280 00:15:56,730 --> 00:15:58,188 Well, I could look at the next one. 281 00:15:58,188 --> 00:16:05,920 I could say, weather[,, 2], and now I see my second matrix, weather[,, 3], 282 00:16:05,920 --> 00:16:08,770 and now I'll see our third matrix, again, 283 00:16:08,770 --> 00:16:12,470 visualizing how these temperatures have changed over time. 284 00:16:12,470 --> 00:16:17,090 So similar to matrix, array does have its own documentation too. 285 00:16:17,090 --> 00:16:20,560 So if I type ?array, to open this documentation, 286 00:16:20,560 --> 00:16:23,920 I can see ways to create an array. 287 00:16:23,920 --> 00:16:25,680 I'll open this up for us here. 288 00:16:25,680 --> 00:16:28,640 And let's look at the usage now for array. 289 00:16:28,640 --> 00:16:31,990 So we saw our very first argument to array 290 00:16:31,990 --> 00:16:34,330 was a parameter that we called data. 291 00:16:34,330 --> 00:16:37,180 And we gave it the value temps, this longer version 292 00:16:37,180 --> 00:16:40,540 of temps to fill in not just one matrix but three. 293 00:16:40,540 --> 00:16:44,230 We then specified the dimensions in terms of a vector. 294 00:16:44,230 --> 00:16:47,260 In this case, we gave it a vector of length 3, where 295 00:16:47,260 --> 00:16:51,340 we asked for three rows, three columns, and three of those structures 296 00:16:51,340 --> 00:16:53,050 to stretch back in time. 297 00:16:53,050 --> 00:16:55,720 And finally, we have a very similar parameter, 298 00:16:55,720 --> 00:17:00,160 dimnames if we wanted to name each of those dimensions, 299 00:17:00,160 --> 00:17:04,329 like, x, y, or z or maybe like longitude, latitude, and time 300 00:17:04,329 --> 00:17:07,180 we could do that here if we wanted to. 301 00:17:07,180 --> 00:17:10,089 So this is a brief foray into how we have 302 00:17:10,089 --> 00:17:13,900 tried to create our own structures using matrices and arrays to represent 303 00:17:13,900 --> 00:17:15,978 temperatures how they can change over time. 304 00:17:15,978 --> 00:17:18,520 I'm excited to see what you all create with these structures. 305 00:17:18,520 --> 00:17:20,550 See you next time. 306 00:17:20,550 --> 00:17:22,000