round()
   get_help() docs


Description

The round() function comes with R and is part of the Base R {base} package.

We use this function to round numbers to a certain number of decimal places.

Conceptual Usage

round(numeric value to round, number of decimal places)
round(numeric array to round, number of decimal places)

Examples

# Round the number 5.355266335 to 2 digits
round(5.355266335, 2)
## [1] 5.36


# Round all values in the array to 3 digits
round(c(3.55511, 6.2351, 7.29315327, 34.253620), 3)
## [1]  3.555  6.235  7.293 34.254


# Round all values in the `carnivores` column `brainwt` to 1 digit using dplyr::mutate()
carnivores %>%
  mutate(brainwt_rounded = round(brainwt, 1))
## # A tibble: 9 × 5
##   name              genus        awake brainwt brainwt_rounded
##   <chr>             <fct>        <dbl>   <dbl>           <dbl>
## 1 Arctic fox        Vulpes        11.5  0.0445             0  
## 2 Cheetah           Acinonyx      11.9 NA                 NA  
## 3 Dog               Canis         13.9  0.07               0.1
## 4 Gray seal         Haliochoerus  17.8  0.325              0.3
## 5 Jaguar            Panthera      13.6  0.157              0.2
## 6 Lion              Panthera      10.5 NA                 NA  
## 7 Northern fur seal Callorhinus   15.3 NA                 NA  
## 8 Red fox           Vulpes        14.2  0.0504             0.1
## 9 Tiger             Panthera       8.2 NA                 NA