Removing regulartable decimal places() flextable package {R}

Asked

Viewed 1,242 times

2

I am making a report in . rmd to export to . docx and to mount the tables I am using the package "flextable" , which works for this type of export. The problem is that when I go to assemble the tables the function adds three decimal places and I cannot remove. 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 the column to ?

  • 1

    Put the.integer on.()

  • Manoel, that worked perfectly, thank you!

1 answer

3


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

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()

inserir a descrição da imagem aqui

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

  • Cool, I was using the round and it wasn’t working. Thank you

  • So Marcus, this works with my fictional example but it doesn’t work with my real problem. In my real problem, when I use regulartable the final number gets like this: 1659.000 , but when I apply formatC with mutate_if - mutate_if(is.Numeric,funs(formatC(., digits=0))) - it returns me 2e+03 . You:And you can tell me what might be going on ?

  • 1

    Use formatC(a, digits=0, format="d").

Browser other questions tagged

You are not signed in. Login or sign up in order to post.