Hi just want to ask on how can I round off the values in my table, into just 2 decimal places. Here are my codes for the table output.
kable(Varimportance$anova, caption= "ANOVA Table")
kable(Varimportance$importance, caption= "Variable Importance")
And this is what my table looks like there are values that has 5, 8 or more decimal places. And I want it to be just 2 decimal places.
You can round off particular condition values based on the rounding figures, like 10th place, 100th place etc. For example, suppose you have a condition type, say ZMOP. The client requirement is to round up the condition values for this condition type to two decimal places. The configuration steps are as follows.
Eigher you explicitly give float or decimal or numeric (xx,x) (x means numeric value) Then it will convert as the data, other wise it round off the last value. Show activity on this post. In my case I was doing the conversion to the correct data type but had decimal (18,0) for the column in the table.
You have to explicitly print the kable () results, and apply the chunk option results = 'asis', e.g., In general, when you generate output from a for -loop, we recommend that you add a few line breaks ( ) or an HTML comment ( <!-- -->) after each output element to clearly separate all output elements, e.g.,
For R Markdown documents, kable () uses the pipe format for tables by default, which looks like this: You can also generate simple tables, or tables in HTML, LaTeX, and reStructuredText: Please note that only the formats pipe and simple are portable, i.e., they work for any output document format.
As suggested in pogibas comment above, use the digits
argument. The default value is getOption("digits")
.
kable(Varimportance$anova, caption= "ANOVA Table", digits=2)
kable(Varimportance$importance, caption= "Variable Importance", digits=2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With