0

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
  • 4,338
  • 6
  • 23
  • 35
josh
  • 63
  • 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

5

Here, in Base-R

tax_data$rate_percent <- round(tax_data$rate_percent ,2)
Daniel O
  • 4,205
  • 5
  • 20