From the course: R for Data Science: Lunch Break Lessons

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

menu

menu

- [Instructor] If you're running an interactive session with R it's nice to give the users some choices or a menu. And R provides the menu command for just exactly this. To demonstrate this, I've created a vector called myChoices and you can see it, it's on the right hand side. It contains four items. Up, Down, Left and right. So let's create a menu that uses those. menu and I type in the vector that I want to use for the items to choose from and you can see that I now have four choices Up, Down, Left and Right. And I can make a selection. So I'm going to select number three and menu returns the selection provided by the user. Now I can enhance menu. If I use menu and then I add a comma and I'm going to type title. I'm going to give this user some idea of what they're been asked for. So in this case Go in this direction and when I hit return I get a title that says Go in this direction Up, Down, Left, Right and I'm going to select one and get one returned. Now you can go one step…

Contents