2014-02-10 26 views
-2

舍入數字我想按一定間距,以數字舍入到的第一個整數,即其中R

if the spacing is s=5 

6.5 -> 5 
8.5 -> 10 

與改變間距s的可能性。我能做到這一點與圓的,但只是10,100,等。

非常感謝

+7

'輪(6.5/5,0)* 5'。 – joran

回答

1

plyr有一個內置的,這是否與花哨的設置(round_any

require(plyr) 
round_any(102.1, 10)    
round_any(99.01, 5, f = ceiling) 
round_any(1.1, 5, f = ceiling) 
round_any(6, 5, f = floor) 
round_any(6.3, 0.25, f = floor)