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.

Infix operator

Infix operator

- Infix operators are a fancy name for operator symbols that go between two variables. Think of them like plus signs or a multiplication sign or division sign. So you can add three plus four, like this, three plus four. And in this case the plus is an infix operator. R provides a way for you to create your own infix operators. And here's how to do it. The first thing you'll need to do is create a function. And up here in the code window you see that I've created something called "%alphasum%". Now there's two important things that I've done. The first is that I've used quotes around the name. And I've also used percent, alphasum, percent. Into that I've placed a function, and the function is fairly easy. It just takes the length of the first string and adds it to the length of the second string. Once I define this, you'll notice in the right-hand corner I have a function called "%alphasum%". I'm down here in the…

Contents