6

Possible Duplicate:
R: += and ++ equivalent from c++/c#/java, etc.?

Does R (specifically a data.frame) have a version of the += operator? I would like to say:

my.df[foo > 50,"foo"] -= 10

But the best I can come up with so far is:

my.df[foo > 50,"foo"] <- my.df[foo > 50,"foo"] - 10

Any help appreciated.

Community
  • 1
  • 1
Ina
  • 4,400
  • 6
  • 30
  • 44
  • 1
    No. There is no such equivalent. – Andrie Jun 12 '12 at 16:52
  • 1
    @joran I must congratulate you on your search-fu. I knew this had been asked before, but couldn't navigate the search either on SO or in Google. – Andrie Jun 12 '12 at 16:55
  • 1
    @Andrie "[r] += increment" did it for me, but it took 2-3 tries before I got there. – joran Jun 12 '12 at 16:56
  • Thanks, I suspected this may have been asked before but I had no idea how to go about searching it. I tried a few variants but got nowhere. – Ina Jun 12 '12 at 17:02
  • @joran: the "+=" is ignored. "[r] increment" is sufficient. – Joshua Ulrich Jun 12 '12 at 17:18
  • 2
    Also duplicates the even earlier: http://stackoverflow.com/questions/7768686/r-self-reference – IRTFM Jun 12 '12 at 17:28
  • That earlier question also usefully references `:=` in `data.table`, which I use often. But, unfortunately, in this case I'm using `data.frame` and don't have access to that. – Ina Jun 12 '12 at 17:31

0 Answers0