A. J. Rossini
2001-Mar-31 18:45 UTC
[R] Is this a bug with a simple arithmetic operation with a vector object?
On Sun, 1 Apr 2001, hzi wrote:> Hello- > > While I was reading a tutorial book for R (actually, for S-Plus:Brian S. Everitt. A Handbook of Statistical Analysis using S-PLUS. Chapman & Hall, London, 1994) I tried to execute this simple exercise: > > > x <- -c(1,2,3,4,5,6) > > X <- -c(10,11,12,100,-5,-6) > >x+X > [1] -11, -13, -15, -104, 0, 0 > > As you can see, the added vectors resulted in negative numbers ! (the answer should have been: [1] 11, 13, 15, 104, 0, 0) > Mind you, this is R 1.2.1 for Windows, under WIndows ME, 64 Mb RAM, pIII 800 MHz. The same thing happens, however, with the recently distributed "R 1.2.2 patched". > Clues, anyone?Of course. "<-" is assignment, but "-c(1,2,3,4,5,6)" = "c(-1,-2,-3...". Well, you get the drift. You've added a negative sign where you don't want one. best, -tony -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley
2001-Mar-31 18:54 UTC
[R] Is this a bug with a simple arithmetic operation with a vector object?
On Sun, 1 Apr 2001, hzi wrote:> Hello- > > While I was reading a tutorial book for R (actually, for S-Plus:Brian S. Everitt. A Handbook of Statistical Analysis using S-PLUS. Chapman & Hall, London, 1994) I tried to execute this simple exercise: > > > x <- -c(1,2,3,4,5,6) > > X <- -c(10,11,12,100,-5,-6) > >x+X > [1] -11, -13, -15, -104, 0, 0 > > As you can see, the added vectors resulted in negative numbers !(the answer should have been: [1] 11, 13, 15, 104, 0, 0) Why? Everitt's book is extremely badly typeset, and `< -' is in fact `<-' not `<- -' as you have entered. But the laws of arithmetic say R was right.> Mind you, this is R 1.2.1 for Windows, under WIndows ME, 64 Mb RAM, pIII 800 MHz. The same thing happens, however, with the recently distributed "R 1.2.2 patched".Why `mind you'? A phrase involving `workmen' and `tools' springs to mind.> Clues, anyone?Find a more reliable (and less outdated) guide .... -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dilip N. Thadani
2001-Mar-31 23:59 UTC
[R] Is this a bug with a simple arithmetic operation with a vector object?
Thats because you have a minus sign before the c. instead of x<- -c(1,2,3..) use x<- c(1,2,3..) cheers dilip -----Original Message----- From: owner-r-help at stat.math.ethz.ch [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of hzi Sent: Sunday, April 01, 2001 4:25 PM To: r-help at stat.math.ethz.ch Subject: [R] Is this a bug with a simple arithmetic operation with a vector object? Hello- While I was reading a tutorial book for R (actually, for S-Plus:Brian S. Everitt. A Handbook of Statistical Analysis using S-PLUS. Chapman & Hall, London, 1994) I tried to execute this simple exercise: > x <- -c(1,2,3,4,5,6) > X <- -c(10,11,12,100,-5,-6) >x+X [1] -11, -13, -15, -104, 0, 0 As you can see, the added vectors resulted in negative numbers ! (the answer should have been: [1] 11, 13, 15, 104, 0, 0) Mind you, this is R 1.2.1 for Windows, under WIndows ME, 64 Mb RAM, pIII 800 MHz. The same thing happens, however, with the recently distributed "R 1.2.2 patched". Clues, anyone? Thank you. Best regards, Henry hzi at uol.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010401/bc4568df/attachment.html
hzi
2001-Apr-01 07:25 UTC
[R] Is this a bug with a simple arithmetic operation with a vector object?
Hello- While I was reading a tutorial book for R (actually, for S-Plus:Brian S. Everitt. A Handbook of Statistical Analysis using S-PLUS. Chapman & Hall, London, 1994) I tried to execute this simple exercise: > x <- -c(1,2,3,4,5,6) > X <- -c(10,11,12,100,-5,-6) >x+X [1] -11, -13, -15, -104, 0, 0 As you can see, the added vectors resulted in negative numbers ! (the answer should have been: [1] 11, 13, 15, 104, 0, 0) Mind you, this is R 1.2.1 for Windows, under WIndows ME, 64 Mb RAM, pIII 800 MHz. The same thing happens, however, with the recently distributed "R 1.2.2 patched". Clues, anyone? Thank you. Best regards, Henry hzi at uol.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010401/2eb13863/attachment.html
Bill Simpson
2001-Apr-01 09:01 UTC
[R] Is this a bug with a simple arithmetic operation with a vector object?
R is working properly:> x <- -c(1,2,3,4,5,6) > x[1] -1 -2 -3 -4 -5 -6> X <- -c(10,11,12,100,-5,-6) > X[1] -10 -11 -12 -100 5 6> x+X[1] -11 -13 -15 -104 0 0 If this is not what you expected, then you must have meant: x <- c(1,2,3,4,5,6) etc You negated the vectors with a minus sign in front of the c(). The assignment operator is <-, not <- - Bill -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._