floor/ceiling result unexpected, due to RStudio table view rounding choice?

R's floor() and ceiling() functions are "inaccurate sometimes" or "can cause unexpected results" which is obviously concerning when math is the one thing in my life I thought I could rely on!

Background here and in ?floor:

Warning
The realities of computer arithmetic can cause unexpected results, especially with floor and ceiling. For example, we ‘know’ that floor(log(x, base = 8)) for x = 8 is 1, but 0 has been seen on an R platform. It is normally necessary to use a tolerance.

See attached picture: my suspicion is that confusion for used can come from the fact that the RStudio data viewer rounds numbers at a certain depth of decimal places (perhaps 6?) whereas floor() and ceiling() don't round. Possibly this is a niche / low importance thing but until you do enough digging and work out the cause, it can be very confusing. Feasibly this could be a global option, "data viewer rounding decimal places", default 6, delete value for no rounding. In my attached example, this would mean rows 228991 & 2 both showed as 11.99999 instead of 12.00000.

Cheers!

RbugFloor|561x500

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.