Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: += (plus equals) and ++ (plus plus) equivalent from c++/c#/java, etc.?

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

like image 560
SFun28 Avatar asked Apr 21 '11 02:04

SFun28


People also ask

Does R have a += operator?

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

What does == do in R?

The Equality Operator == Relational operators, or comparators, are operators which help us see how one R object relates to another. For example, you can check whether two objects are equal (equality) by using a double equals sign == .

What is increment in R?

increment: IncrementAdds one to given variable and returns this computed variable. Function is used by main function "estimationFunction" and shall not be called or changed by user.


2 Answers

No, it doesn't, see: R Language Definition: Operators

like image 115
Patrick Cuff Avatar answered Sep 25 '22 16:09

Patrick Cuff


Following @GregaKešpret you can make an infix operator:

`%+=%` = function(e1,e2) eval.parent(substitute(e1 <- e1 + e2)) x = 1 x %+=% 2 ; x 
like image 22
baptiste Avatar answered Sep 22 '22 16:09

baptiste