课程: R Code Challenges: Data Science

今天就学习课程吧!

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

Solution: Fizz buzz

Solution: Fizz buzz

- [Instructor] Now fizzBuzz may seem like a kid's game, but it's actually a really good demonstration of how R approaches large sets of numbers. We often call them vectors. With R, you don't need to use any flow control statements. You don't need to use for or if or while, you can do all of this manipulation just simply using vectors. Let's demonstrate how I solve this problem. In line eight, I create a function called fizzBuzz. I'm going to go ahead and define that, and then in line 31, I call that function with fizz equal to two and buzz equal to seven. What that produces for us is a named vector, and by named I mean that each value in the vector has a name. In this case, it's one or two or three or four. And it has a value. It's kind of like key value pairs. So item number one has the character value of one, item number two has a character value of fizz and so on. Let's step through each line in the function that I created and examine how I solve this problem. We'll start in line…

内容