Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounding off values in the Kable

Tags:

r

r-markdown

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.enter image description here

like image 902
Bustergun Avatar asked Feb 26 '18 07:02

Bustergun


People also ask

How to round off particular condition values based on rounding figures?

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.

How do you round off the last value in a table?

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.

How to print Kable results from a for loop?

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.,

What format does Kable use for tables?

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.


1 Answers

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)
like image 162
patrickmdnet Avatar answered Oct 26 '22 04:10

patrickmdnet