Dear R users, I am using R version 2.0.1 (2004/11/15) on an i386-pc-mingw32 platform. I encounter the following problem while using cumsum:> a <- rep(0.01, 100) > b <- cumsum(a) > sum(a) == 1[1] TRUE> b[100] == 1[1] FALSE Am I missing something? Should cumsum have such an outcome? Thanks in advance for any clarifications any of you can offer. Regards, Makram Talih -- Makram Talih, Ph.D. Assistant Professor Department of Mathematics and Statistics Hunter College of the City University of New York 695 Park Avenue, Room 905 HE New York, NY 10021 Website: http://stat.hunter.cuny.edu/talih E-mail: talih at math.hunter.cuny.edu Tel: 212-772-5308 Fax: 212-772-4858
On 29 May 2005 at 20:17, Makram Talih wrote: | Dear R users, | | I am using R version 2.0.1 (2004/11/15) on an i386-pc-mingw32 platform. I | encounter the following problem while using cumsum: | | > a <- rep(0.01, 100) | > b <- cumsum(a) | > sum(a) == 1 | [1] TRUE | > b[100] == 1 | [1] FALSE | | Am I missing something? Yes, FAQ section 7.31 entitled "Why doesn't R think these numbers are equal?". | Should cumsum have such an outcome?> a <- rep(0.01, 100) > b <- cumsum(a) > sum(a) == 1[1] FALSE> all.equal(sum(a), 1)[1] TRUE> all.equal(b[100], 1)[1] TRUE>On my Linux system with R 2.1.0, the first equality fails whereas it "worked" for you. Morale: don't forget about floating-point math ... Hth, Dirk -- Statistics: The (futile) attempt to offer certainty about uncertainty. -- Roger Koenker, 'Dictionary of Received Ideas of Statistics'
R help document showed us that you should not use "==" for comparing objects, and you will use "all.equal". -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Makram Talih Sent: Monday, May 30, 2005 8:17 AM To: r-help at stat.math.ethz.ch Subject: [R] trouble with cumsum? Dear R users, I am using R version 2.0.1 (2004/11/15) on an i386-pc-mingw32 platform. I encounter the following problem while using cumsum:> a <- rep(0.01, 100) > b <- cumsum(a) > sum(a) == 1[1] TRUE> b[100] == 1[1] FALSE Am I missing something? Should cumsum have such an outcome? Thanks in advance for any clarifications any of you can offer. Regards, Makram Talih -- Makram Talih, Ph.D. Assistant Professor Department of Mathematics and Statistics Hunter College of the City University of New York 695 Park Avenue, Room 905 HE New York, NY 10021 Website: http://stat.hunter.cuny.edu/talih E-mail: talih at math.hunter.cuny.edu Tel: 212-772-5308 Fax: 212-772-4858 ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __________________________________________________ 佈伵伝仮伱佲伔佈G佊伿佅佷仯伃佒佇伖侜伒佢佉伝伨侙佄佫伬伂伝侙佊伿伡侢伾仹伻伵伋伂伌侒佊伿佅佷