Dr.jeon
Dr.jeon

Reputation: 15

rounding of numbers using R

I want to convert the following numbers in this way I tried to use all possible methods but i am unable to get the value which i expected

value        round off value
0.0 - 4.9         0
5.0 - 5.9         6
6.0 - 6.9         7
7.0 - 7.9         8
8.0 - 8.9         9
9.0 - 10.0        10

The above table is for reference

expected output  eg :- roundup(5.0) = 6  ,roundup(6.9)=7

Upvotes: 0

Views: 53

Answers (1)

nicola
nicola

Reputation: 24520

You can try:

roundup<-function(x) c(0,6:10)[findInterval(x,c(0,5:9))]
roundup(c(5,6.9))
#[1] 6 7

Upvotes: 1

Related Questions