From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

R data types: Matrix

R data types: Matrix

- [Narrator] When you're programming in r, there are several data structures that you'll want to be aware of. Vectors, lists, matrices, arrays, data frame, and factors. Let's talk about matrices. Now matrices are vectors with attributes of a dimension and optionally, dimension names attached to the vector. Let's create some data to work with. First of all create a vector. And into that vector, I'll place some strings. All right, there's a very simple vector. And we can ignore the warning here. This is six elements, and it contains characters. Let's create a matrix based on that. It's done like this. A matrix, that's the name of the object that we'll place this into. And we're going to place into it a matrix. We're going to use the vector that we just created. And we're going to give it a number of rows. So n row equals two. And a number of columns, so n col equals three. Now if I hit return, you'll see that I now have a matrix. And if you look at the structure over here, I have two…

Contents