[R] Is this a bug with a simple arithmetic operation with a vector object?

Dilip N. Thadani thadani at tkk.att.ne.jp
Sun Apr 1 01:59:59 CEST 2001


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


More information about the R-help mailing list