小编Tam*_*m R的帖子

在RStudio中编织默认RMarkdown文件时出错

我正在使用运行R版本3.5.1的RStudio版本1.1.456。我在Windows 7 Enterprise(64位)上运行。

我是R Markdown的新手,因此,当我在RStudio中打开一个新的R Markdown文件时,我认为最好在自己尝试任何操作之前运行默认代码。(注意:这是打开新的Rmd文件时自动填充的代码)。

---
title: "test"
output: html_document
---

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

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. …
Run Code Online (Sandbox Code Playgroud)

markdown rstudio r-markdown

4
推荐指数
1
解决办法
2055
查看次数

格式化 Flextable 中特定列的数字

我在 RStudio 中使用 R 版本 3.6.1。我有flextable版本0.5.5和officer版本0.3.5。

我在 RMarkdown 中格式化弹性表中的数字时遇到困难。默认情况下,所有数字均显示为小数点后 3 位。对于我的一些数字,这很好(实际上是首选),但对于其他数字,我想删除小数。

使用此处的建议,我能够调整我的表格,以便所有数字都四舍五入到最接近的整数。我的代码如下(用于再现性的示例表;其他格式与我当前的代码相同)。

ft_test <- head(iris) %>% flextable() %>% 
    hline(part = 'header', border = fp_border(color = "black", width = 3)) %>% 
    align(align ='center', part = 'all') %>% 
    align(j = 1, align ='left', part = 'all') %>% 
    set_formatter_type(fmt_double = "%.0f")
ft_test
Run Code Online (Sandbox Code Playgroud)

但是,我只希望某些列是整数,而其他列仍然有小数。我尝试使用j参数来调用某些列:

ft_test <- head(iris) %>% flextable() %>% 
    hline(part = 'header', border = fp_border(color = "black", width = 3)) %>% 
    align(align ='center', part = 'all') %>% 
    align(j = 1, …
Run Code Online (Sandbox Code Playgroud)

r flextable r-markdown

3
推荐指数
1
解决办法
8804
查看次数

标签 统计

r-markdown ×2

flextable ×1

markdown ×1

r ×1

rstudio ×1