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

Unlock this course with a free trial

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

Arrays and outer

Arrays and outer

- [Instructor] Generating the outer product of two matrices is a complex process, but R provides a simple way to do it. Let's take a look at the outer product of two matrices and two vectors. Let's start with vectors. So I'll create vector one and vector two. Now, the formula for the outer product of two vectors looks like this. It's vector one with a dot product of the transpose of vector two. Now R provides the outer function, so it's outer and we can type in vector one and vector two and you'll see that we return the exact same result. R also provides a wrapper for outer, and I'll explain why they do this here in a minute, but it looks like vector one %O%, vector two. And you'll notice that all three versions produce the exact same result. Now, let's look at producing the outer product of two matrices. So for that I'll need two matrices, I'll create matrix A and matrix B and let's take a look at those real quick…

Contents