The numbers in this data.frame are rounded to 3 decimal places:
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
I need them rounded to 2 decimal places. I tried to use plyr::l_ply like this:
library(plyr)
l_ply(habitats_df[,2:3], function(x) round(x, 2))
But it didn't work. How can I use plyr:: l_ply to round the numbers in habitats_df?