课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

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

Vectorize

Vectorize

- [Instructor] R is all about applying functions to vectors. And there is a function in R called vectorize. It's a little bit difficult to understand, but once you understand it, it gives you the essence of R. So let's take a look at this very interesting command. To start off, I've created a function called myIf, you can see it up here, in the code window, and when I run it, you can see that the environment now has a function called myIf. I'm going to clear the console here and let's demonstrate what it does. myIf and if I give it 3,4 what I return is, 3 and 4 They Don't Match. If I give myIf two values that do match, say 1 and 1, then I receive the message that 1 and 1, match. So obviously it's a pretty simple function but let's use this now to demonstrate how it works with vectorize. With R you often want to pass a range of numbers or a vector into a function, and in the function using vector math will…

内容