 Hi everyone, it's MJ and welcome back to this course on R. In this video, we're gonna be talking about data structures. So let's maybe go through a little bit of theory and that is in R, everything is an object. Now, instead of making every single data point its own object, we can organize the data into a structure that then becomes its own object. And this helps the computer work faster and more efficiently. Now, there are some common data structures such as vectors, lists, matrices, data frames, and arrays. And in this video, just because we're conscious of time, we're gonna focus on the two most popular ones which are vectors and data frames. So let's maybe start off with vectors. Vectors are one-dimensional data structures with homogenous elements of a given length. Now, homogenous just means similar and the opposite of homogenous is heterogeneous which means different. And a list is similar to a vector in the sense that it's also a one-dimensional data structure but this time a list will have heterogeneous elements of a given length. So that's the difference between a list and a vector is what type of elements we're looking at. But let's focus on vectors and let's look at some examples of our vectors. Now, to create these in R, we use simply this function called C and then we open up the brackets and we just list them inside. So if I was to actually do this in R, so in R I would then type in days equals C, open up my brackets and then if it's a string, I need the quotation marks and then I'm gonna separate them with the comma. So I would type that into R, I would then type in days and then R will display. So the output I'm representing here in the red. So what makes vectors quite cool is that let's say I had to take my vectors, which is now days and I say I wanna extract the second element, I then say days and then with square brackets, I put the element I wanna extract, so I put that in and we'll see that the answer of R, it comes back with Tuesday. Now, I can also have a starting point and an end point. So if I want the second day all the way up to the fourth day, we hit enter in R and we'll get Tuesday, Wednesday, Thursday. What's also cool is we can pass a vector in the square bracket. So let's create a new vector called odd. So all the odd numbers are one, three, five and seven and then if we say days and in the square bracket we put a vector, we see that we'll get all the odd-numbered days, Monday, Wednesday, Friday, Sunday. Now your vectors can also be manipulated and you can do calculations on them. So if I take my vector of odd and I multiply it by itself, we'll get a new vector, which is now the square roots, yeah, sorry, the square of each of those odd numbers. So one, nine, 25 and 49. And we can also do simple maths like odd plus one and then we'll get all of the even numbers. So we can see that you can do operations on vectors and you can also extract elements from your vector. And remember, vectors, one-dimensional homogenous elements. Now compare this to say the data frame where now we have two dimensions. So it's a two-dimensional data structure with heterogeneous elements of a given length. And what we're gonna see is that this is kind of like a table and storing data in a table is the most popular object in R. And you can also think of it as a list of vectors of equal length. Now every column in every row needs a name and because it's a list, each column can have different data types. So you can have strings in the one column, you can have integers in the next. But because it's a list of vectors, not a list of lists, it's a list of vectors, it means each element in the column must be the same type. So if we've got a column of strings, you don't wanna have an integer in that column. You wanna keep them all of the same type. And let's maybe look at a very quick example of a data frame and here you can see it's those three vectors, it's a list of these three vectors and we've got number, day, temperature. So how would we create this in R? It turns out to be very, very simple, very straightforward. So in R, we would create our vectors. So we have days equals C, open the brackets, type in the information that you need. And then what you do is you create a new object. So we can call ours weatherframe and we say equals data.frame and now in the brackets, we're just going to list our vectors. And then if we had to type in weatherframe, the R output would be as follows. What's also quite cool with the data frames is just like with the vectors, you can put in the position. So if I had to say weatherframe one, what this will then return would be the days vector. And why we want our information in these data frames is because then it's very easy to visualize this data. So we could come and plot, we just say plot weatherframe and we can now visualize our data. Of course, that's a very ugly looking plot and what we're going to be doing in the next video is looking at graphs and data visualizations and slowly start moving to, okay, it's not that much better, but we've got color, we've got a few extra elements as well, but we will be discussing that in the next video. Thanks so much for watching and I'll see you then.