round_any equivalent for dplyr?

前端 未结 1 2050
野性不改
野性不改 2020-12-20 12:01

I am trying to make a switch to the \"new\" tidyverse ecosystem and try to avoid loading the old packages from Wickham et al. I used to rely my coding previously. I

相关标签:
1条回答
  • 2020-12-20 12:26

    ggplot::cut_width as pointed to in one of the comments, does not even return a numeric vector, but a factor instead. So it is no real substitute.

    Since round and not floor is the default rounding method, a custom replacement until a (dplyr solution may arrive) would be

    round_any = function(x, accuracy, f=round){f(x/ accuracy) * accuracy}
    

    This method could also be used directly from the plyr package which contains this implementation. However, be careful when loading plyr into a workspace which will cause naming conflicts when using dplyr as well.

    0 讨论(0)
提交回复
热议问题