Chapter 8

Putting the Fun in Functions

In This Chapter

arrow Automating your work with functions

arrow Playing with arguments

arrow Finding objects within the functions

arrow Working with methods

Automating your work is probably the number one reason why you use a programming language. You can get pretty far with the built-in functions of R in combination with scripts, but scripts aren’t very flexible when dealing with variable input. Luckily, R allows you to write your own custom functions (for example, to automate the cleaning of your data, to apply a series of analyses with one command, or to construct custom plots).

The functions that you write yourself are essentially the same as many of the built-in functions — they are first-class citizens. In this chapter, you discover how to write and work with functions in R.

Moving from Scripts to Functions

Going from a script to a function doesn’t take much effort at all. A function is essentially a piece of code that is executed consecutively and without interruption. In that way, a function doesn’t differ that much from a script run using the source() function, ...

Get R For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.