小编M. *_*ott的帖子

如何使用 R 中的 markdown 抑制 knitr 块选项中的 dev.off() 消息

我不想在我的 .rmd 文件中拆分我在 RStudio 中编写的代码块。

我的全局选项是:

{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, autodep = T, message = FALSE, warnings = FALSE, cache=TRUE, messages=FALSE)
Run Code Online (Sandbox Code Playgroud)

甚至我的块选项是:

{r section025, message=FALSE, warning=FALSE}
code here
Run Code Online (Sandbox Code Playgroud)

PDF 输出在页面中间显示以下内容,我在代码中保存了图像:

## pdf 
## 2
Run Code Online (Sandbox Code Playgroud)

我似乎已经使用了所有抑制选项,所以我无法弄清楚为什么仍然出现。思想赞赏。

markdown r knitr

5
推荐指数
2
解决办法
2592
查看次数

在R中,使用dplyr的mutate()创建一个以另一个的内容为条件的新变量

我想搜索一个变量的内容placement,并term根据所寻找的模式创建一个新变量.一个最小的例子......

首先,我创建一个搜索模式函数:

calcterm <- function(x){    # calcterm takes a column argument to read
    print(x)
    if (x %in% '_fa_') {
            return ('fall')
    } else if (x %in% '_wi_') {
            return('winter')
    } else if (x %in% '_sp_') {
            return('spring')
    } else {return('summer')
    }
}
Run Code Online (Sandbox Code Playgroud)

我将创建一个小数据框,然后我将传递给dplyr tbl_df:

placement <- c('pn_ds_ms_fa_th_hrs','pn_ds_ms_wi_th_hrs' ,'pn_ds_ms_wi_th_hrs')
hours <- c(1230, NA, 34)

d <- data.frame(placement, hours)

library(dplyr)

d <- tbl_df(d)
Run Code Online (Sandbox Code Playgroud)

表d现在显示为:

>d
    Source: local data frame [3 x 2]

       placement hours
          (fctr) (dbl)
1 …
Run Code Online (Sandbox Code Playgroud)

r

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

标签 统计

r ×2

knitr ×1

markdown ×1