1
在此data.frame的數字四捨五入至小數點後3位:回合多個向量與plyr
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
中的數字?