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.

upper.tri and lower.tri

upper.tri and lower.tri

- [Instructor] When you're working with matrices in R you're going to need to find the upper or lower triangle. And not surprisingly, R has a command for that. So let's take a look. First, I need a matrix. So in line four, I'll create test matrix, which is just a standard matrix. Let's take a look at it. Five rows, five columns, very simple. Now, let's find the upper and lower triangle of test matrix. First, for reference we'll pull it up and take a look at it. And then I'm going to pull up the upper triangle using upper dot tri. And I specify test matrix. Now what you'll see is false and true. If you look carefully, you can see that row one, column two, is true. Row one, column three, is true and so on. So the upper triangle in the right-hand corner is all true. Likewise, if I look at the lower dot tri as specified in line 15 of the code, you'll see that this is reversed. The lower half of the triangle is true and the…

Contents