Skip to content
Prev 346847 / 398498 Next

rounding down with as.integer

On 31/12/2014 8:44 PM, David Winsemius wrote:
I don't think the original problem was stated clearly, so I'm not sure
whether this is a solution, but it looks wrong to me.  If you want to
round to the nearest integer, why not use round() (without the
as.integer afterwards)?  Or if you really do want an integer, why add
0.1 or 0.0001, why not add 0.5 before calling as.integer()?  This is the
classical way to implement round().

To state the problem clearly, I'd like to know what result is expected
for any real number x.  Since R's numeric type only approximates the
real numbers we might not be able to get a perfect match, but at least
we could quantify how close we get.  Or is the input really character
data?  The original post mentioned reading numbers from a text file.

Duncan Murdoch