【发布时间】:2014-01-24 08:41:47
【问题描述】:
此 data.frame 中的数字四舍五入到小数点后 3 位:
habitats_df <- data.frame(habitat = c("beach", "grassland", "freshwater"), v1 = c(0.000, 0.670, 0.032), v2 = c(0.005, 0.824, 0.012))
habitat v1 v2
1 beach 0.000 0.005
2 grassland 0.670 0.824
3 freshwater 0.032 0.012
我需要将它们四舍五入到小数点后 2 位。我尝试像这样使用plyr::l_ply:
library(plyr)
l_ply(habitats_df[,2:3], function(x) round(x, 2))
但它没有用。如何使用plyr:: l_ply 对habitats_df 中的数字进行四舍五入?
【问题讨论】: