many languages have shorthands for that operation like: variable += 1 or ++variable is there something like that in R ? -- View this message in context: http://r.789695.n4.nabble.com/increase-or-decrease-variable-by-1-tp3076390p3076390.html Sent from the R help mailing list archive at Nabble.com.
On 07.12.2010 14:43, madr wrote:> > many languages have shorthands for that operation like: > > variable += 1 > or > ++variable > > is there something like that in R ?No. Uwe Ligges
On Tue, Dec 7, 2010 at 8:43 AM, madr <madrazel at interia.pl> wrote:> > many languages have shorthands for that operation like: > > variable += 1 > or > ++variable > > is there something like that in R ?You can do this:> x <- 3 > `+`(x) <- 1 > x[1] 4 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
x+1 is not that complicated... Am I missing something here? Le 12/7/2010 16:55, Gabor Grothendieck a ?crit :> On Tue, Dec 7, 2010 at 8:43 AM, madr<madrazel at interia.pl> wrote: >> many languages have shorthands for that operation like: >> >> variable += 1 >> or >> ++variable >> >> is there something like that in R ? > > You can do this: > >> x<- 3 >> `+`(x)<- 1 >> x > [1] 4 > > >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
Indeed! x <- x + 1 (and being generous with unnecessary spaces) uses 10 characters. `+`(x)<-1 (being mean with them) uses 9. The "mean" version of the first uses only 6: x<-x+1 However, I suppose there is merit in the spiritual exercise of contemplating how `+`(x)<-1 gets worked out! Ted. On 07-Dec-10 16:23:17, Ivan Calandra wrote:> x+1 is not that complicated... Am I missing something here? > > Le 12/7/2010 16:55, Gabor Grothendieck a ?crit : >> On Tue, Dec 7, 2010 at 8:43 AM, madr<madrazel at interia.pl> wrote: >>> many languages have shorthands for that operation like: >>> >>> variable += 1 >>> or >>> ++variable >>> >>> is there something like that in R ? >> >> You can do this: >> >>> x<- 3 >>> `+`(x)<- 1 >>> x >> [1] 4 > -- > Ivan CALANDRA-------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 07-Dec-10 Time: 16:42:44 ------------------------------ XFMail ------------------------------
Seemingly Similar Threads
- how to get rid of unused space on all 4 borders in plot() render
- [beginner] simple keyword to exit script ?
- longer object length is not a multiple of shorter object length
- I need a very specific unique like function and I don't know even how to properly call this
- please show me simple example how to plot "Distance-Weighted Least Squares" fitting