Trademark
Trademark

Reputation: 151

++ operator in R

This is really not so important but it would save some typing and make things look nicer occasionally. Is there anything like the C++ ++ operator in R? In other words is there an shorthand for i<-i+1? I don't really want to use it in loops which one should avoid in R anyway but I have a code with a list of matrices and want to increase or decrease numbers by one each time something happens (it is a simulation of a process), so I have to type something like listname[[i]][j,k] <- listname[[i]][j,k] + 1. Thanks.

Upvotes: 2

Views: 971

Answers (1)

Istvan
Istvan

Reputation: 8562

I think you can use inc from Hmisc.

inc(x) <- 1

The dec function does the reverse operation, it subtracts instead of add.

Upvotes: 4

Related Questions