1

How do I round the numbers to 2 decimal points within a column within a dataframe?

The name of the df is tax_data and the column that I want to round is called rate_percent

I tried using:

format(round(rate_percent ,2), nsmall =2) but this didn't work.

Does anyone have any suggestions?

user438383
  • 5,716
  • 8
  • 28
  • 43
josh
  • 73
  • 1
  • 5
  • Here is a `tidyverse` option to replace the values in the rate_percent column with the rounded version. `tax_data %>% mutate(rate_percent = round(rate_percent, 2))` –  Apr 28 '20 at 15:32

1 Answers1

6

Here, in Base-R

tax_data$rate_percent <- round(tax_data$rate_percent, 2)
micstr
  • 5,080
  • 8
  • 48
  • 76
Daniel O
  • 4,258
  • 6
  • 20