如何在 R 中对列中的数字进行舍入?

jos*_*osh 1 r rounding dplyr tidyverse

如何将数据框中的列内的数字四舍五入到小数点后两位?

df 的名称是tax_data,我想要舍入的列称为rate_percent

我尝试使用:

format(round(rate_percent ,2), nsmall =2) but this didn't work.
Run Code Online (Sandbox Code Playgroud)

有没有人有什么建议?

Dan*_*l O 6

在这里,在 Base-R 中

tax_data$rate_percent <- round(tax_data$rate_percent, 2)
Run Code Online (Sandbox Code Playgroud)