Hello All. I am running R 2.0.0 with a Win XP operating system. The same problem occured with R 1.9.1 but not with R.1.3.1 on a Win NT computer. My request is about the following problem with the sort function: The vector price is a vector of 789 asset prices of the following form,> mode(price)[1] "numeric"> price[1:10][1] 1.1315 1.1314 1.1313 1.1314 1.1315 1.1316 1.1315 1.1317 [9] 1.1316 1.1316 Then the returns are defined to be the differences,> ret <- diff(price) > ret[1:10][1] -1e-04 -1e-04 1e-04 1e-04 1e-04 -1e-04 2e-04 -1e-04 [9] 0e+00 0e+00 Here R recognizes the first two entries and also the second ones to be equal (I did not found any two equal entries, where R didnt recognized this relation),> ret[1]==ret[2][1] TRUE> ret[3]==ret[4][1] TRUE But after sorting the vector, this ist not longer true,> s <- sort(ret) > s[1:10][1] -5e-04 -5e-04 -5e-04 -5e-04 -5e-04 -4e-04 -4e-04 -4e-04 [9] -4e-04 -4e-04> s[1]==s[2][1] FALSE Taking the difference of the first two entries yields> s[1]-s[2][1] -2.220446e-16 which seems to be a numerical artefact. Is this a bug, or just a handling error by me? Thanks a lot for your answers, Kay Frederik Pilz Ruhr-Universitaet Bochum Germany Kay.Pilz at rub.de
> x <- 1.00000001 > all.equal(x, 1)[1] TRUE> x == 1[1] FALSE Reading help(all.equal) will tell you that the tolerance level by default is around 1.490116e-08. On Fri, 2004-11-05 at 13:48, Kay Pilz wrote:> Hello All. > > I am running R 2.0.0 with a Win XP operating system. The same problem occured > with R 1.9.1 but not with R.1.3.1 on a Win NT computer.So, which version are you having this problem with ?> My request is about the following problem with the sort function: > > The vector price is a vector of 789 asset prices of the following form, > > > mode(price) > [1] "numeric" > > price[1:10] > [1] 1.1315 1.1314 1.1313 1.1314 1.1315 1.1316 1.1315 1.1317 > [9] 1.1316 1.1316 > > Then the returns are defined to be the differences, > > > ret <- diff(price) > > ret[1:10] > [1] -1e-04 -1e-04 1e-04 1e-04 1e-04 -1e-04 2e-04 -1e-04 > [9] 0e+00 0e+00 > > Here R recognizes the first two entries and also the second ones to be equal > (I did not found any two equal entries, where R didnt recognized this > relation), > > > ret[1]==ret[2] > [1] TRUE > > ret[3]==ret[4] > [1] TRUE > > But after sorting the vector, this ist not longer true, > > > s <- sort(ret) > > s[1:10] > [1] -5e-04 -5e-04 -5e-04 -5e-04 -5e-04 -4e-04 -4e-04 -4e-04 > [9] -4e-04 -4e-04 > > s[1]==s[2] > [1] FALSE > > Taking the difference of the first two entries yields > > > s[1]-s[2] > [1] -2.220446e-16 > > which seems to be a numerical artefact. > > Is this a bug, or just a handling error by me? > > Thanks a lot for your answers, > Kay Frederik Pilz > Ruhr-Universitaet Bochum > Germany > Kay.Pilz at rub.de > > ______________________________________________ > 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 >
Kay Pilz <Kay.Pilz at ruhr-uni-bochum.de> writes:> Hello All. > > I am running R 2.0.0 with a Win XP operating system. The same problem occured > with R 1.9.1 but not with R.1.3.1 on a Win NT computer. > > My request is about the following problem with the sort function:...> Taking the difference of the first two entries yields > > > s[1]-s[2] > [1] -2.220446e-16 > > which seems to be a numerical artefact. > > Is this a bug, or just a handling error by me?You, I think. Consider for instance> x <- c(1.313,1.314,1.315,1.316) > diff(x) - 1e-3[1] 1.118897e-16 -1.101549e-16 1.118897e-16> sort(diff(x) - 1e-3)[1] -1.101549e-16 1.118897e-16 1.118897e-16> diff(sort(diff(x) - 1e-3)[1:2])[1] 2.220446e-16 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Maybe Matching Threads
- [Bug 80769] New: [NVD9] GF119M boot hang with 3.15.2
- smtp_address_cmp does not ignore case of localpart
- Panic: file message-part-serialize.c: line 90 (part_serialize): assertion failed: (part->children == NULL)
- Power analysis and sample size calculation for nonlinear regression
- Path to R script