Reputation:
In math, we can approximate a number such this:
Suppose we have x
and y
with these values:
x = 0.35
and
y=0.67
Then the approximate of x
and y
are, x=0.4
and y=0.7
.
I would like to know how to do this in r.
round
function seems to be unable to deal with this issue.
Upvotes: 0
Views: 4037
Reputation: 302
The function round it works good, the way you need to use it is that you need to put the digits like:
x <- 0.34
round(x, digits = 1)
# [1] 0.3
x <- 0.37
round(x, digits = 1)
# [1] 0.4
Upvotes: 0