The example here puzzles me. It seems like the operator doesn't work as
expected.
l - 0.6
u - seq(0.4, 0.7, 0.1)
u
[1] 0.4 0.5 0.6 0.7
mygrid - expand.grid(l = l, u = u)
mygrid
l u
1 0.6 0.4
2 0.6 0.5
3 0.6 0.6
4 0.6 0.7
mygridcollapsed - mygrid[mygrid$l mygrid$u, ]
You need to back up a bit to see the root cause of
the problem, which is that seq()'s calculations necessarily
involve some roundoff error (since it works with 52 binary
digits of precision):
u - seq(from=0.4, to=0.7, by=0.1)
u - c(0.4, 0.5, 0.6, 0.7)
[1] 0.00e+00 0.00e+00
This is R FAQ 7.31, about machine representation of
floating point numbers.
mygrid$u[3] - mygrid$l[3]
[1] 1.110223e-16
So
mygrid$l[3] mygrid$u[3]
is true, though the difference is very, very small and due solely
to the limitations of computers.
Sarah
On Thu, Feb 2, 2012 at 5:00 AM, Jonas Hal
It's likely an infelicity of floating point representations (R FAQ
7.31) but admittedly, not a case I would have expected to present
itself.
If you want it to work out as expected, try this:
l - 0.6
u - seq(0.4, 0.7, 0.1)
l.int - (6L) / 10
u.int - seq(4, 7) / 10
l u
l.int u.int
Michael
On
On Thu, Feb 02, 2012 at 10:00:58AM +, Jonas Hal wrote:
The example here puzzles me. It seems like the operator doesn't work as
expected.
l - 0.6
u - seq(0.4, 0.7, 0.1)
u
[1] 0.4 0.5 0.6 0.7
mygrid - expand.grid(l = l, u = u)
mygrid
l u
1 0.6 0.4
2 0.6 0.5
3 0.6 0.6
5 matches
Mail list logo