Does R have a concept of **+=** (plus equals) or **++** (plus plus) as c++/c#/others do?

0 votes

In R, there is no concept of increment operator but you can make a function that performs the same function as an increment operator.

For example:

`++` <- function(x) eval.parent(substitute(x <-x +1))

a <- 1

a

[1] 2

`%+=%` = function(e1,e2) eval.parent(substitute(e1 <- e1 + e2))

x = 1

x %+=% 2

x

[1] 3