user9589138
user9589138

Reputation:

How to approximate a number in R

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

Answers (2)

Nicolas Rosewick
Nicolas Rosewick

Reputation: 1998

With round :

x <- 0.35
round(x,digits=1)
# [1] 0.4

Upvotes: 4

J0ki
J0ki

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

Related Questions