Increment operators like "+=" in R?

16,863 views
Skip to first unread message

Allen

unread,
Nov 20, 2012, 3:05:08 AM11/20/12
to davi...@googlegroups.com
Hi, All,
There are increment operators in many other programming languages, where x=x+1 can be written as x++ or x+=1. But R doesn't seem to have things like this.
So are there easier ways to write code for

Noam Ross

unread,
Nov 20, 2012, 9:45:48 AM11/20/12
to Davis R Users Group
R does not have an increment operator in base language, but it's implemented in the `Hmisc` package.  Instead of writing

    x <- x +1

you write

    inc(x) <- 1

The `dec` function does the same, but subtracts instead of adds.
Reply all
Reply to author
Forward
0 new messages