 Now, let's move on to factors, and we're going to begin by creating a new section. So factors are another common data type used in R, and these are used to store categorical variables. So an example would be our respondent wall type variable that we used before that contained different building materials that these houses were constructed from. In those cases, all of the houses kind of fell into different categories, either mud dog, bird brick, sun bricks. And so essentially you can bin all of the different houses in those categories, okay? Similarly, these factors can be either ordered or unordered. In the case of respondent wall type, for instance, there's no kind of natural ordering or sequence to those different levels, okay, or categories. Whereas if we were talking about something like Olympic medals, we would have gold, silver, and bronze, which do implicitly have this kind of ordering, okay? So let's go to an example to highlight some of the kind of special properties of factors. We're going to begin by creating a new variable, which is going to be called respondent floor type. And here we're going to use a new function called factor. Again, because we're creating a vector, you want to use the combined function here within those parentheses. And we're going to insert four values here, earth, cement, other cement, and go ahead and create that. And respondent floor type will appear up here in your global environment. So you can already see within our, this kind of overview here, this is a factor, which has two levels, okay? The four elements, but they all fall into one of these two categories, either cement or earth, okay? And here you're going to see something interesting. You might expect to see actual earth and cement, these kind of string variables or string values that we inserted, but instead, r is actually storing these as integers. So instead of earth and cement, it's basically coded earth as a two and coded cement as a one. And you might wonder why is it that earth, even though it comes first in this list, why is that coded as a two or cement is coded as a one? The reason for that is just because c comes before e and r naturally kind of codes these things in alphabetical order. So again, there are some functions that we can use here to kind of inspect our new variable. So the levels function, I choose my respondent floor type here. This is going to tell me now what my two levels are here, cement and earth, okay? Likewise, I could use the in levels just to return the number of levels that contain that vector. And here we have two. So I mentioned that sometimes these factor variables actually have an order that's important to respect. So the way that you can kind of tell r that this is an ordered factor is by just adding an additional argument. So just to kind of run through this example, I'm going to create a new variable here called metals. And again, I'm going to throw in here three kind of levels of metals you can earn of gold, silver and bronze. And now here between these two parentheses. So after this argument, I'm going to add a second argument, which says ordered, okay, equals true. And this just tells r that again, these are factors with an order that's important to respect, okay? And in this case, you can see when I read this, that r is going to say we have these three elements here, but bronze is less than gold, which is less than silver, okay? All this is saying now is that there's an order that's being stored here along with the actual levels of that factor, but you might notice that r doesn't really know what bronze, gold and silver mean. And so it's saying that gold is less than silver. It's doing that again because of alphabetical order. B comes before G, which comes before S. If I wanted to specify that the order matters, okay, that gold is more than greater than silver, I could do that with an additional argument here. So again, I'm going to reassign this variable. And this time I'm going to use this additional argument levels, okay? And I'm going to say, let's put these, I'm just going to copy these over, but I'm going to put them in the order that I want them to be stored, okay? So I'm going to put gold at the end here, bronze at the beginning. And if I run it this time in print metals, now you can see that it's been reordered with bronze being less than silver, being less than gold, okay? So now I have the order that I want to just by using this additional argument here.