How to Call a Function in R Programming for Predictive Analytics

By Anasse Bari, Mohamed Chaouchi, Tommy Jung

Functions are lines of code that do something useful and concrete. Because these operations are often repeated in a predictive analytics project, they are usually saved with a name so you can call (use) them again. Typically a function takes an input parameter, does something with it, and outputs a value. You save functions in your own programs or libraries for future use.

There are many built-in functions in the R programming language for developers to use. You’ve already used the str() function to find out the structure of a variable.

Calling a function will always be in the same form: the function name followed by parentheses. (Inside the parentheses is the parameter list that may or may not be empty).

Whenever you start to suspect that the operation you’re doing must be common, check to see whether a function exists that does it for you. Getting to know all the built-in functions in R will greatly improve your productivity and your code. Having a cheat sheet or reference card of all the built-in functions is handy when you’re learning a new language.

Here is a link to an R reference card.