【问题标题】:How to print specific columns in with htmlTable in RMarkdown?如何在 RMarkdown 中使用 htmlTable 打印特定列?
【发布时间】:2017-09-10 06:50:05
【问题描述】:

我很喜欢使用 RMarkdown 创建报告,最近发现了 htmlTable 包。

我使用子集函数从一个大型 data.frame 创建多个报告/表格。但是,我不确定如何仅打印特定列。例如,我当前的代码如下所示:

```{r echo=FALSE}
library("htmlTable")
htmlTable(subset(iris, Species=="setosa"),
          align="rrrr|r",
          rnames = FALSE,
          header =  paste(c("Sepal Length", "Sepal Width",
                            "Petal Length", "Petal Width", "Species")))
```

如果我只想打印 Sepal LengthPetal LengthSpecies 列,我将如何与子集一起执行此操作?

谢谢。

【问题讨论】:

    标签: r html-table r-markdown


    【解决方案1】:

    似乎是一个直截了当的 R 子集问题。

    out<-iris[iris$Species=="setosa", c("Sepal.Length", "Petal.Length", "Species")]
    
    htmlTable(out,
          align="rrrr|r",
          rnames = FALSE)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      相关资源
      最近更新 更多