R round to nearest .5 or .1

后端 未结 4 468
忘了有多久
忘了有多久 2020-11-27 15:44

I have a data set of stock prices that have already been rounded to 2 decimal places (1234.56). I am now trying to round to a specific value which is different

4条回答
  •  忘掉有多难
    2020-11-27 16:09

    The taRifx package has just such a function:

    > library(taRifx)
    > roundnear( seq(.1,1,.13), c(.1,.1,.1,.2,.3,.3,.7) )
    [1] 0.1 0.2 0.3 0.4 0.6 0.6 0.7
    

    In your case, just feed it the stock price and the minimum tick increment as its first and second arguments, and it should work its magic.

    N.B. This has now been deprecated. See comment.

提交回复
热议问题