R: Trying to make a summary table and round the values

Viewed 174

I am making a summary table in R and trying to round the values to 3 decimal places but the rounding is not happening for all of the columns. Here is my code

#summarize the needed data
      achesy_data<-aches_young %>% group_by(age) %>% 
        summarize(
          'sample size' = n(),
          mean = mean(height),
          'standard deviation' = sd(height),
          'coefficient of variation' = sd(height)/mean(height),
          Q1 = quantile(height, 0.25), 
          median = median(height),
          Q3 = quantile(height, 0.75),
          'IQR' = IQR(height)
        )
    #round to 3 decimals
      achesy_data <- achesy_data %>%
        mutate_if(is.numeric, round, 3) %>%
        as.data.frame()

This is the output of my table.

enter image description here

As you can see Q1 and median do not have 3 decimal places but the other columns do. I have no clue what I am doing wrong or what I can do to fix this.

0 Answers
Related