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

Unlock this course with a free trial

Join today to access over 24,100 courses taught by industry experts.

missing

missing

- [Instructor] How does a function deal with a missing argument? There's a couple of ways to do this. One of them is the function called missing, and let's take a look at how to use that. To start, I've defined a simple function called imaFunction, and I'll go ahead and define that by clicking on line 4 and then clicking on the run button. And you can see that I now have a function called imaFunction, and we can run that. Let's run line 9, and all it does is add the three arguments that are passed into the function. So dArg, eArg, and zArg, 3, 4, 5 added together equals 12. Nothing complex, but how does imaFunction operate if zArg is missing? So let's go ahead and delete that, and we'll go ahead and run line 9, and you can see that we get an error message that zArg is missing with no default. Well there's a couple of ways to solve this. If it's just a simple missing value, you can set a default value. So we can go…

Contents