What's in R programming 1

Programming with R: Everything that happens is a function call

R is an implementation of the S programming language that was created in the 1970s by John Chambers was developed at Bell Labs. R was written from 1992 by Ross Ihaka and Robert Gentleman and distributed from 1993; it has existed since 1997 R Development Core Team, of which John Chambers is a member. The following quote comes from Chambers, which characterizes the main features of R:

Everything that exists is an object.
All that happens is a function call.

Everything is a function call

How literally the second part of the quotation is to be taken is illustrated below: Even unsuspicious characters like “+” and “-” are functions. Proof:

3 + 4 [1] 7 > "+"(3, 4) [1] 7

Since the plus sign is not a "normal" letter, it must be enclosed in quotation marks (double or single, so-called. backticks) can be set. Otherwise it works like other function calls: Function name (parameter 1, parameter 2), like about
mean (x, na.rm = TRUE).

> 10 - 3 [1] 7 > "-"(10, 3) [1] 7

This also applies to the minus sign ...

21 / 3 [1] 7 > "/"(21, 3) [1] 7

... as for divisions and (not shown above) for multiplications "*".

The math operators are called infix operators denotes: they stand between, not before the function parameters (prefix). Further infix operators are marked with% signs, e.g. B.% in% to check whether certain characters appear in a vector, or% *% for matrix multiplications. The high flexibility of R also includes the possibility of defining your own infix operators.

Also the so-called. subsetting, i.e. access to individual elements of data structures with square brackets, is a function call:

mtcars [1, 3] [1] 160> "[" (mtcars, 1, 3) [1] 160

Recommended literature:


Author Wolf RieplPosted on Categories Practical example, R programmingTags functional programming, programming