I am trying to produce a markdown table using knitr::kable where the rounding of digits varies by rows. For example, suppose I have the following data.frame:
exa
As pointed out by @user20650, one solution consists in converting the format of the entries in your dataframe in R
before passing the data to knitr
. It could be done like this:
example.df <- rbind(formatC(as.numeric(example.df[1,]),format="f",digits=2),
formatC(as.numeric(example.df[2,]),format="d"))
colnames(example.df) <- c("a","b")
This gives the following output:
> kable(example.df, align="r")
| a| b|
|----:|----:|
| 0.12| 0.57|
| 2000| 3000|