[R] Increment element of vector and efficiency

Roger D. Peng rpeng at jhsph.edu
Thu Nov 20 14:56:38 CET 2003

I think that's about as efficient as you can get.  I'm not sure of the 
underlying details.  There was some discussion recently of having the 
equivalent of a "+=" operator but currently R has no such thing.


Pascal A. Niklaus wrote:
> Hi all,
> Thanks for the incredibly quick help with the "%in%"...
> There's a second question, though: I'd like to increment an element of a 
> vector if a certain event occurs, e.g.
>    count[event] <- count[event] + 1;         # works, but...
> Is this efficient? I wonder whether R needs to subset the count vector 
> on both sides of the assignment operator (i.e., twice), or whether 
> there's a shortcut like "++" in C, e.g. "count[i]++" or similar?
> Pascal
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

More information about the R-help mailing list