Mik*_*kko 8 r rounding plyr dplyr tidyverse
我正试图切换到"新" tidyverse生态系统,并试图避免加载Wickham 等人的旧包装.我过去常常依赖我的编码.我发现round_any功能从plyr在许多情况下有用的地方,我需要定制四舍五入为图,表格等EG
x <- c(1.1, 1.0, 0.99, 0.1, 0.01, 0.001)
library(plyr)
round_any(x, 0.1, floor)
# [1] 1.1 1.0 0.9 0.1 0.0 0.0
Run Code Online (Sandbox Code Playgroud)
是否有round_any与plyr包相同的功能tidyverse?
Hol*_*ndl 13
ggplot::cut_width正如其中一条评论所指出的,甚至不会返回数字向量,而是返回一个因子.所以它不是真正的替代品.
由于round而不是floor默认的舍入方法,因此在(dplyr解决方案可能到达)之前进行自定义替换
round_any = function(x, accuracy, f=round){f(x/ accuracy) * accuracy}
Run Code Online (Sandbox Code Playgroud)