kable

Conditionally formatting cells in one column by comparing it with the value from another column using Kable

偶尔善良 提交于 2019-12-25 01:46:09
问题 I am new to R and we know in Excel it is very easy to conditionally format a cell (change the background colour) by comparing with another column. I tried to do this in R using KableExtra. But I could not succeed in fetching value from another row and comparing it. My task was making a cell to appear green, yellow or red by comparing a cell on another column in the same row. library(kableExtra) library(dplyr) library(knitr) multirow_spec <- function(x, rows, ...) { for (row in rows) x <-

how to combine multiple html (kable) tables into one image?

心已入冬 提交于 2019-12-24 15:15:19
问题 I would like to combine several kable tables into one single image. Something like: library(knitr) library(kableExtra) dt <- mtcars[1:5, 1:4] # first table table1 <- kable(dt, format = "html", caption = "Demo Table") %>% kable_styling(bootstrap_options = "striped", full_width = F) %>% add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>% add_footnote(c("table footnote")) # second table table2 <- kable(dt, format = "html", caption = "Demo Table") %>% kable_styling(bootstrap_options

How to group columns in R markdown?

与世无争的帅哥 提交于 2019-12-24 08:47:19
问题 I am trying to generate a table using kable and saving the output as a markdown. I am later using pandoc to convert markdown to pdf. For my table I would like to group my table columns into two groups. It seems that this could be achieved using the kableExtra "add_header_above" function, but unfortunately the output cannot be stored as markdown. Is there a way to group columns using markdown? I am pasting my dummy code below. Appreciate all comments and suggestions. library(knitr) library

Rmarkdown : can we merge two cells with kableExtra?

好久不见. 提交于 2019-12-24 00:36:35
问题 Is there a way to merge two cells with kableExtra when knitting from Rmarkdown to HTML? bbb = 5 aaa = data.frame(matrix(c(1,2,3,4, paste(bbb),""), nrow = 2, byrow = T)) aaa I want the value bbb (the value of the merged cells varies) to appear in the middle of the last two columns when applying kable(aaa) %>% kableExtra(...) > aaa X1 X2 X3 1 1 2 3 2 4 5 Any suggestion ? Thanks :-) 来源: https://stackoverflow.com/questions/58132626/rmarkdown-can-we-merge-two-cells-with-kableextra

Reduce spacing between columns in table created with kable(, format = 'markdown')

霸气de小男生 提交于 2019-12-23 10:16:26
问题 I try to create a table using the format "markdown" of the function kable() , but the spaces between the columns are so wide that the table extends over the page. Is there anyway to adjust the cell size so that a table in markdown format does not extend over the page? In latex format it stays within the page, but I do not want this format nor do I want html . I want the output file to be .pdf. I know that a similar question has been asked here, but my question is specific to the format

Reduce spacing between columns in table created with kable(, format = 'markdown')

我的未来我决定 提交于 2019-12-23 10:15:36
问题 I try to create a table using the format "markdown" of the function kable() , but the spaces between the columns are so wide that the table extends over the page. Is there anyway to adjust the cell size so that a table in markdown format does not extend over the page? In latex format it stays within the page, but I do not want this format nor do I want html . I want the output file to be .pdf. I know that a similar question has been asked here, but my question is specific to the format

kableExtra only works if there's another table in the presentation?

做~自己de王妃 提交于 2019-12-21 17:54:52
问题 When I use kableExtra for a PDF output, the table renders beautifully, BUT gives an error if there isn't another, non-kable extra table in the program. Has anyone else seen this behavior? the file appears to knit fine, but then throws an error in pandoc? For example, this code: --- output: beamer_presentation: fontsize: 10pt --- ```{r global_options, include=FALSE} library(rmarkdown) library(knitr) library(kableExtra) ``` ### Slide with table ```{r echo=FALSE, warning=FALSE, message=FALSE} df

KableExtra conditionally formatting specific rows on a column

独自空忆成欢 提交于 2019-12-21 06:45:26
问题 I have just learnt KableExtra and know to how to use conditionally formating the entire column using mutate() as explained in the doc using mutate such as: mutate( mpg = cell_spec(mpg, background = ifelse(mpg > 20, "red", "blue")) ) But what I don't know is, how to change background colours of only certain rows in each column whilst all rows are being displayed. For example, my data: df <- data.frame( region1 = c("A", sample(1:5,3)), region2 = c("B", sample(1:5,3)), region3 = c("C", sample(1

Kable caption in rmarkdown file in HTML in bold

爱⌒轻易说出口 提交于 2019-12-13 03:33:05
问题 I want to make my table caption in bold but can't seem to find the option for it. My code is (in a rmarkdown document): kable(head(iris), caption = 'I want this in Bold') %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) The output is: 回答1: Does this markdown-oriented solution work for you? ```{r, results='asis'} kable(head(iris), caption = '**I want this in Bold**') %>% kableExtra::kable_styling(bootstrap_options = c("striped", "hover", "condensed",

Table way too wide to fit in Markdown generated PDF

烂漫一生 提交于 2019-12-13 01:34:58
问题 I am trying to display a table from an SQL query to a pdf by using Rmarkdown. However, the table I get is too wide and it does not fit in the document. I have been recommended to use the Pander package, and so I tried to use the pandoc.table() function which works greatly on the console, but for some reason it stops my document from rendering in Rmarkdown. The code looks kinda like this : rz = dbSendQuery(mydb, "select result.id result_id, company.id company_id, (...)") datz = fetch(rz, n=-1)