[R] seq

Petr Pikal petr.pikal at precheza.cz
Fri Sep 3 14:02:55 CEST 2004



On 3 Sep 2004 at 13:41, Roger Bivand wrote:

> On Fri, 3 Sep 2004, Henric Nilsson wrote:
> 
> > Hi everyone,
> > 
> > I've tried the below on R 1.9.1 and the 2004-08-30 builds of R 1.9.1
> > Patched and R 2.0.0 on Windows 2000, and the results are consistent.
> > 
> >  > seq(0.5, 0, by = -0.1)
> > [1] 0.5 0.4 0.3 0.2 0.1 0.0
> > 
> >  > seq(0.7, 0, by = -0.1)
> > [1]  7.000000e-01  6.000000e-01  5.000000e-01  4.000000e-01 
> > 3.000000e-01 2.000000e-01  1.000000e-01 -1.110223e-16
> > 
> > Is this really the intended behaviour? I ended up using
> 
> Well, you are using a floating point representation in a digital
> computer, so I don't think you should be surprised. Note that the
> internal representation is also modified by the print() functions, so
> what you see when an object is printed is not always exactly what is
> inside the object.
> 
> > 
> >  > seq(0.7, 0, length = 8)
> > [1] 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.0
> > 
> > which does what I want.

Hi

Are you sure?

> seq(0.7, 0, length = 8)-c(0.7,0.6,0.5,0.4,0.3,0.2,0.1,0)

[1]  0.000000e+00  0.000000e+00  0.000000e+00 -5.551115e-17  
0.000000e+00
[6]  0.000000e+00 -2.775558e-17  0.000000e+00
>

> sum(seq(0.7, 0, length = 8)-c(0.7,0.6,0.5,0.4,0.3,0.2,0.1,0))
[1] -8.326673e-17
> sum(seq(0.7, 0, length = 8)-c(0.7,0.6,0.5,0.4,0.3,0.2,0.1,0))==0
[1] FALSE
>

Cheers
Petr


> > 
> > //Henric
> > 
> > ______________________________________________
> > 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
> > 
> 
> -- 
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School
> of Economics and Business Administration, Breiviksveien 40, N-5045
> Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail:
> Roger.Bivand at nhh.no
> 
> ______________________________________________
> 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

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list