课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

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…

内容