Removing decimal places regulartable () flexible package {R}

2

I am making a report in .rmd to export to .docx and to mount the tables I am using the "flextable" package, which works for this type of export. The problem is that when I mount the tables the function adds three decimal places and I can not remove it. Example:

df <- data.frame(a = c(0,1,2,3,4,5), b = c("x", "y", "z", "w", "j", "k"))

df %>%
flextable::regulartable()

How can I remove the decimal places from column a?

    
asked by anonymous 23.07.2018 / 19:45

1 answer

2

It seems that flextable does not allow you to format the number of decimal places in the output of the numbers. But nothing prevents us from using the formatC function for this:

library(tidyverse)
library(flextable)

df <- data.frame(a = c(0,1,2,3,4,5), b = c("x", "y", "z", "w", "j", "k"))

df %>% 
  mutate(a=formatC(a, digits=0)) %>% 
  regulartable()

I simply added an extra line to your code. Before generating the table itself, I replaced the column a with itself, but formatted to display 0 digits. I could have put other values into the argument digits in order to format the number with the number of decimal places I wanted.

    
23.07.2018 / 20:03