Functional Programming in R

Functional Programming:

In many ways, R can be considered a functional programming language. Functions can be passed as arguments to functions and returned as values. But other aspects of functional programming are also available in R. The functions are written in R, and hence do not provide performance improvements over performing the computations from the first principles, but that could change. They do however provide useful abstractions and can yield code that is easier to comprehend. It is instructive to look at the implementations.

Types of Functional Programming in R:

Four functions are part of R that implement some of the ideas of functional programming.
Reduce It takes a function of two arguments and an input vector and successively combines the elements of that vector.

Filter: It extracts the elements of a vector conditional on a logical function, returning true when applied to that element.

Map: It applies a function to the corresponding elements of an arbitrary number of input vectors. It is a lot like the apply family of functions, and if named arguments are given, where the names match the name of a formal argument to the function being mapped, it is used.

Negate: It creates a negation of a given function.