首页 > 解决方案 > 如何在 R Markdown 表中包含存储的值?

问题描述

R Markdown 初学者在这里。有没有办法可以在 R 降价表中包含存储的值?例如,假设我有价值

x <- 20

如何在这样的表中包含 x:

|       Col1      |         Col2         |

|:----------------|:--------------------:|

| Row1            | [where x should be]  | 

只是写 x 显然会在编织后返回字母,而不是所需的值。任何帮助表示赞赏,干杯!

标签: rr-markdown

解决方案


这是一个显示使用反引号的可重现示例。

---
title: "Variables in tables"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
x = 1
cell = 'hello world'
```

## R Markdown

First Header  | Second Header
------------- | -------------
`r cell`  | Content Cell
Content Cell  | `r x`

推荐阅读