【发布时间】:2021-04-27 20:45:19
【问题描述】:
由于我是 RMarkdown 和/或 R 的新手,我在以下方面遇到了一些麻烦:
我想在 RMarkdown 中将 vtable(使用库 vtable 创建)显示为普通的 kable 表(我正在使用 LaTex 创建 PDF)。我知道 vtable 可以返回一个 knitr kable,因此它可以用作 kable_styling 的输入,所以我可以修改乳胶选项。这似乎在一定程度上起作用。
这是目前为止的代码:
vtable(heart_faliure_data, labels = label) %>%
kable_styling(latex_options = c("striped", "scale_down"))
为什么要显示latex命令?
感谢您能给我的任何帮助。
数据库可以在这里找到:https://archive.ics.uci.edu/ml/datasets/Heart+failure+clinical+records
这里是完整的 Rmd 文件:
---
title : "Data mining using R for heart failure clinical records Dataset"
floatsintext : yes
figurelist : yes
tablelist : yes
footnotelist : no
linenumbers : no
linkcolor : "blue"
mask : no
draft : no
classoption : "doc"
output : papaja::apa6_pdf
documents
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
---
```{r include = FALSE}
library("tidyverse")
library("kableExtra")
library("rsample")
library("recipes")
library("parsnip")
library("yardstick")
library("viridisLite")
library("GGally")
library("vtable")
library("qwraps2")
library("ggplot2")
library("htmlTable")
library("egg")
library("dplyr")
library("afex")
library("papaja")
library("kableExtra")
library("magrittr")
library("vtable")
knitr::opts_chunk$set(echo = TRUE)
heart_faliure_data <- read.csv(file = "../Data/heart_failure_clinical_records_dataset.csv", header = FALSE, skip=1)
c_names <- c("Age",
"Anaemia",
"cr_ph",
"diabetes",
"ejection_fraction",
"high_blood_pressure",
"platelets",
"serum_creatinine",
"serum_sodium",
"sex",
"smoking",
"time",
"DEATH_EVENT")
colnames(heart_faliure_data) <- c_names
```
\newpage
# Introductiom
```{r echo=FALSE}
knitr::kable(head(heart_faliure_data), booktabs = TRUE) %>%
kable_styling(latex_options = c("striped", "scale_down"))
```
```{r echo=FALSE}
label <- data.frame(
Age = "Age of the patient",
Anaemia = "Decrease of red blood cells or hemoglobin",
creatinine_phosphokinase = "level of the CPK enzyme in the blood (mcg/L)",
diabetes = "if the patient has diabetes",
ejection_fraction = "percentage of blood leaving the heart at each contraction",
high_blood_pressure = "if the patient has hypertension",
platelets = "platelets in the blood (kiloplatelets/mL)",
serum_creatinine = "level of serum creatinine in the blood (mg/dL)",
serum_sodium = "level of serum sodium in the blood (mEq/L)",
sex = "sex of the patient, woman or man",
smoking = "if the patient smokes or not",
time = "follow-up period",
DEATH_EVENT = " if the patient deceased during the follow-up period"
)
vtable(head(heart_faliure_data), labels = label, out="latex") #%>%
kable_styling(latex_options = c("striped", "scale_down"))
```
您好!
编辑:代码格式
【问题讨论】:
-
我添加了必要的信息
-
问题中有指向数据集的链接(“UCI 机器学习存储库:心力衰竭临床记录数据集”archive.ics.uci.edu/ml/datasets/Heart+failure+clinical+records)。确实,您不需要 .bin 文件来重现它。我会摆脱他们。
标签: r latex r-markdown vtable kableextra