【发布时间】:2017-09-23 11:19:31
【问题描述】:
我正在尝试切换到“新”tidyverse ecosystem 并尝试避免从 Wickham 等人加载旧包。我以前依赖我的编码。我发现plyr 中的round_any 函数在我需要对绘图、表格等进行自定义舍入的许多情况下很有用。例如
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
在tidyverse 的 plyr 包中是否有与 round_any 等效的函数?
【问题讨论】:
-
没有,但功能很简单,在本例中为
floor(x / 0.1) * 0.1。为避免加载包,请使用::表示法:plyr::round_any。 -
好像换成了
ggplot2::cut_width。见github.com/tidyverse/ggplot2/releases/tag/v2.0.0
标签: r dplyr rounding plyr tidyverse