课程: R Code Challenges: Data Science

今天就学习课程吧!

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

Solution: Create a random door code

Solution: Create a random door code - R教程

课程: R Code Challenges: Data Science

Solution: Create a random door code

- [Instructor] Creating a door code that looks like a date can be done several ways. You could solve this problem additively, where you select a valid year, and then a valid month, and then a valid date. Or what I chose to do is subtractive. I created a list of all the available dates, and then chose one, and then reformatted it to fit the appropriate format. Let's take a look at how I did that. Here's a function called uniqueDoorCode. In line 2, I set up a loop by declaring candidateCode equal to one, and I know this is a false value, so it will loop at least once. In line 4 is where I set up the while loop and I test for all unique values in candidateCode that are greater than or equal to six. This is going to check to make sure that the number that I've chosen has a unique set of numbers. Now how do I create that candidateCode? Let's start in line 5. I'll select that line and then run it. And I now have a value called candidateCodes with one through, huh, a lot of values. Let's…

内容