 It's LinkedIn learning author Monica Wahee with today's data science makeover. Watch while Monica Wahee demonstrates how to create a matrix in R and then coerce it into a data frame. Hi everyone today I'm going to show you how to make a matrix from scratch. Remember what a matrix is? It's an object in R. One of the tabular objects R has. Honestly, I don't like matrices much. Personally when I have a matrix I always convert it to a data frame. So here's the code we are going to run to make the matrix. We see a word and then an arrow. This means we are making something. Obviously we are making a matrix. In this case the matrix is going to be called zero underscore matrix. And you will see why in a moment. So here we are with the matrix command. And we are going to get into an argument. Actually three arguments. So the first argument, well I'm kind of cheating with the first argument. This says what to put in the middle of the matrix. I'm just demonstrating what to do. So I put a zero. That means in each cell meaning each intersection of a column and a row in the matrix, R is going to put a zero. I say I'm cheating because usually this part is more complicated. But I just want a zero for demonstration purposes. Our second argument is n row equals three. That means we want three rows. I just pick that number. And our last argument is n call equals five. I think we want five columns. So if we get what we want we will run this and get a matrix that's three rows long, five columns wide and filled with zeros. Let's see what happens. Okay now let's run our new matrix. See that in the console? Great. Perfect. Looking good so far. But remember how I don't like anything but data frames? This is a matrix, not a data frame. I'll prove it to you by running this class command on this zero underscore matrix. If you want more information on the class command, look in the description. I linked to a video. See over here? It says matrix. We thought it would do that. But I wanted to be a data frame since as you know, I prefer data frames. I can coerce it to be a data frame by using this code. See this code? I'm using the as dot data dot frame command as data frame. I'm converting the matrix into a data frame named zero underscore df. See how the as data frame is spelled as dot data dot frame? And it has one argument and that's the matrix, our zero underscore matrix. So let's run this and see if we are successful in forcing this zero underscore matrix into a data frame format. Well it ran. To make sure it did what we think it did, let's run this class command below it here. This is to see if the class of zero underscore df is really a data frame. So I'm going to run it. There, see it in the console? Zero underscore df is indeed a data frame. So you know I'm partial to data frames. But often I'm building a data frame. Like an analytic data set that I'm going to analyze. On the way I often need to add different things. Like for example a bunch of columns that have zeros in them which I will update later with code. Two state flags. What I showed you here is one of my tricks. Making a matrix then converting it to a data frame. Then I can patch it onto some other data frame I'm building. And then when I'm done that clumsy awkward matrix is a gorgeous data frame. And now that you've had your data science makeover, you have a gorgeous day. Thank you for watching this data science makeover with LinkedIn Learning author Monica Wahee. Remember to check out Monica's data science courses on LinkedIn Learning. Click on the link in the description.