Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加粗特定数据帧R的最后第8行_R_Dataframe_Html Table_Dplyr - Fatal编程技术网

加粗特定数据帧R的最后第8行

加粗特定数据帧R的最后第8行,r,dataframe,html-table,dplyr,R,Dataframe,Html Table,Dplyr,我在下面提到了数据框架: Type A B C D A1 1 1 0 2 A2 2 1 1 0 A3 1 0 2 0 ... A7 1 0 1 0 Sum 5 2 4 2 对于上面的数据框,我想加粗最后一行Sum,并将其涂成黄色。在rmarkdown文件.Rmd中,我们这样做了 --- title: "Markdown" author: "akrun" da

我在下面提到了数据框架:

Type   A    B    C   D
A1     1    1    0   2
A2     2    1    1   0
A3     1    0    2   0
...
A7     1    0    1   0
Sum    5    2    4   2

对于上面的数据框,我想加粗最后一行
Sum
,并将其涂成黄色。

在rmarkdown文件
.Rmd
中,我们这样做了

---
title: "Markdown"
author: "akrun"
date: "February 27, 2018"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Table

```{r code1, include = FALSE, cache = FALSE}
library(dplyr)
library(knitr)
library(kableExtra)

df1 <- structure(list(Type = c("A1", "A2", "A3", "A7", "Sum"), 
     A = c(1L, 2L, 1L, 1L, 5L), B = c(1L, 1L, 0L, 0L, 2L), 
     C = c(0L, 1L, 2L, 1L, 4L), D = c(2L, 0L, 0L, 0L, 2L)), 
     .Names = c("Type", "A", "B", "C", "D"), class = "data.frame", 
      row.names = c(NA, -5L))


```


```{r code2, echo = FALSE }
kable(df1, "html") %>%
       kable_styling("striped", full_width = F) %>%
       row_spec(nrow(df1), bold = TRUE, color = "white", background = "yellow")

```
-输出


这是在文件中写入的吗?@akrun否,然后我会将其转换为html表格。您可以检查@akrun感谢分享,这真的非常有帮助,您能帮我解决我的问题,仅将最后一行加粗。当然,我将作为解决方案发布如何在我现有的代码中执行类似操作:
Table1%tableHTML(rownames=FALSE,widths=rep(100,13),second_headers=list(c(1,6,6),c(“,“ABC”,“XYX”)),caption=“ABC Stat”)%%>%add_css_caption(css=list(c(“字体重量”,“边框”),c(“粗体”,“1px纯黑”))%%>%add_css_行(css=list(c(“背景色”)、c(“浅蓝色”)、行=0:2)%>%添加标题(css=list(c(“背景色”)、c(“浅蓝色”))
@Roy1245更新了帖子。根据原始数据集更改
宽度
。请在此处帮助我在现有代码中仅加粗最后一行的黄色背景。该操作有效,但最后一行尚未加粗。@Roy1245我正在检查,抱歉,在那里找不到选项
---
title: "Markdown"
author: "akrun"
date: "February 27, 2018"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Table


```{r code1, include = FALSE, cache = FALSE}
library(dplyr)
library(knitr)    
library(tableHTML)

df1 <- structure(list(Type = c("A1", "A2", "A3", "A7", "Sum"), 
     A = c(1L, 2L, 1L, 1L, 5L), B = c(1L, 1L, 0L, 0L, 2L), 
     C = c(0L, 1L, 2L, 1L, 4L), D = c(2L, 0L, 0L, 0L, 2L)), 
     .Names = c("Type", "A", "B", "C", "D"), class = "data.frame", 
      row.names = c(NA, -5L))

```


```{r code2, echo = FALSE }

df1 %>% 
  tableHTML(rownames = FALSE, widths = rep(c(100, 50), c(1, 4)), 
             second_headers = list(c(1, 2, 2), c("", "ABC", "XYZ"))) %>%
  add_css_caption(css = list(c("font-weight", "border"), c("bold", "1px solid black"))) %>%
  add_css_row(css = list(c("background-color"), "yellow"), rows = nrow(df1)+2) %>%
  add_css_caption(css = list("background-color", "lightblue"))



```