Search code examples
rfloor

why does floor return in this example one element less


I am running R version 3.1.1 (2014-07-10) -- "Sock it to Me" and there should be something that I am missing with respect to the floor function since I would expect the latest integer to be 25 in the following example:

a = 50.8
b = 25.9
floor(a:b)

Note however that the following works as expected:

c = 10.96
d = 9.3
floor(c:d)
c = 10.96
d = 9.9
floor(c:d)

Solution

  • You don't understand :. The documentation says

    For other arguments from:to is equivalent to seq(from, to), and generates a sequence from from to to in steps of 1 or -1.

    The last value that can be reached from 50.8 by subtracting multiples of 1 without surpassing 25.9 is 26.8. And floor(26.8) is 26.