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

Unlock this course with a free trial

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

Backslash lambda functions

Backslash lambda functions

- [Instructor] R 4.1 was recently released, and as part of the package, it includes a lambda function. So let me show you how this new notation works. Normally, when you declare a function, you use the function command. So let's create a function called bob, and we're going to place a function with a parameter called myvariable, myvar. And we're going to multiply that var by two. So if I declare bob three, I'll get back three times two, which equals six. That's a standard function definition. Now with 4.1, this changes just a little bit. You can use function, but you can also use the lambda symbol. So in this case, we'll type in bob and instead of typing in function, I can type in a backslash. Then I'll type in myvar, which is the parameter I want to pass in, and two times myvar. So I'd encourage you to compare the upper definition to the lower definition. And again, when I type in bob three, there it is. I…

Contents