我想以幻灯片的形式显示data.frame的内容。我知道如何使用ascii库从data.frames创建Markdown表,但是当我尝试使用它时,没有在输出html中看到表,而是看到了一堆关于ascii表内部结构的信息。
那么,如何在幻灯片中打印头部(some.data.frame)呢?
编辑:
实际上,我想在CRAN Task视图中显示一个视图表,现在我在Markdown中手动输入了该表:
Views | Content
--------|--------
Bayesian| Bayesian Inference
ChemPhys| Chemometrics and Computational Physics
ClinicalTrials| Clinical Trial Design, Monitoring, and Analysis我想从ctv包中自动创建这个表。我已经在一个data.frame中收集了我需要的信息:
library(ctv)
list.of.views <- available.views()
X <- data.frame(View=NA,Description=NA)
for(i in 1:length(list.of.views))
{
X[i,1] <- list.of.views[[i]]$name
X[i,2] <- list.of.views[[i]]$topic
}
head(X)这会导致
View Description
1 Bayesian Bayesian Inference
2 ChemPhys Chemometrics and Computational Physics
3 ClinicalTrials Clinical Trial Design, Monitoring, and Analysis
4 Cluster Cluster Analysis & Finite Mixture Models
5 DifferentialEquations Differential Equations
6 Distributions Probability Distributions我使用ascii包进行标记
library(ascii)
print(ascii(X[1:6,1:2]), type = 'pandoc')它显示在R终端中:
**View** **Description**
--- ----------------------- -------------------------------------------------
1 Bayesian Bayesian Inference
2 ChemPhys Chemometrics and Computational Physics
3 ClinicalTrials Clinical Trial Design, Monitoring, and Analysis
4 Cluster Cluster Analysis & Finite Mixture Models
5 DifferentialEquations Differential Equations
6 Distributions Probability Distributions
--- ----------------------- -------------------------------------------------
Warning messages:
1: In rep(rownames, length = nrow(x)) :
'x' is NULL so the result will be NULL
2: In rep(colnames, length = ncol(x)) :
'x' is NULL so the result will be NULL但是,当我的Rmd文件中的代码块中的最后一行Rmd代码行和slidify文件中的代码块中的最后一行内容时,我在幻灯片中看到了以下内容:
## <S4 Type Object>
## attr(,".xData")
## <environment: 0x03b904d8>
## attr(,"class")
## [1] "asciiTable"
## attr(,"class")attr(,"package")
## [1] "ascii"发布于 2013-09-16 09:12:56
多亏了Tyler Rinker,我成功地使用xtable创建了我想要的表
---
```{r, results='asis'}打印(xtable(X1:6,1:2),type = "html")
发布于 2013-09-16 10:38:11
如果您想要降价,我可以强烈推荐我的拉皮条包,它可以将R对象转换成不同的标记格式方言。简单的例子:
有许多全局或自定义选项来调整表(如对齐、拆分设置、高亮单元格等)。
https://stackoverflow.com/questions/18810749
复制相似问题