课程: R Code Challenges: Data Science

今天就学习课程吧!

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

Solution: Play rock, paper, scissors, lizard, spock

Solution: Play rock, paper, scissors, lizard, spock - R教程

课程: R Code Challenges: Data Science

Solution: Play rock, paper, scissors, lizard, spock

- [Instructor] I like this challenge because it really points out who's thinking like an R programmer, and who comes to this from a different programming language. Oftentimes, people will try to solve the rock paper scissors lizard Spock challenge with a long, long list of if else statements. Our strength is manipulating matrices. So I looked at how can I use a matrix to solve this problem? In the code you're looking at, you can see I've created a couple of things. The first thing I'll need is rock, paper, scissors, lizard, Spock, a vector with the words rock, paper, scissors, lizard, Spock, and I do that in line one. I've already defined that 'cause I'll use that list several times. In line three, I set up the function player1, player2, these are the choices that I'll pass into who won. Then in line six through 15, I set up the truth table or a matrix that I'll use to test player1 against player2. Let's create that matrix. And I will skip through lines 6, 7, 8, 9, 10, and then line…

内容