I have a data frame like this:
> summary
variable value
1 var1 5.810390e-06
2 var2 5.018182e-06
3 var3 5.414286e-06
4 var4 3.000779e+02
5 var5 -2.105123e+01
6 var6 8.224229e-01
I want to print it in a word document using knitr/kable. Thus I used the following function:
knitr::kable(summary,
row.names = FALSE,
col.names = c("Variable", "Mean"))
But the result is not satisfying:
I'm OK with variables 4 to 6, but variables 1 to 3 are really not easy to read this way... Is there a way to control this format?
The most general way is to do the formatting yourself, and send a dataframe of character variables to kable. For example, this doesn't give the nicest display, but it shows how to handle the first 3 rows separately:
This produces the following output:
You can also use
as.character()
andsignif()
:Which gives: