English 中文(简体)
如何导出 R 中的 HTML 表格, 并控制线边界?
原标题:How to export HTML table in R and have control over line borders?
  • 时间:2012-05-27 13:20:39
  •  标签:
  • r

R 中是否有任何功能允许将 HTML 表格作为 R Markdown 或相关编织文档的一部分出口,并允许详细控制表格线边框?

例如,想象一下这样的矩阵:

x <- matrix(c("", "M", "F", "Good", 
"23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE)

什么样的命令会输出具有以下特征的适当的 HTML 表格 :

       --------
       M     F
---------------
 Good  23    17
---------------
 Bad   23    4
---------------
最佳回答

你可以尝试一下我这个非常年轻的软件包, 名称是pander , 试图用 打印R对象, http://johnmacfarlane.net/pandoc/"rel="noreferr">pandoc 标记格式。

懒惰的例子:

> x <- matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE)
> pandoc(x)

+------+------+------+
|      | M    | F    |
+------+------+------+
| Good | 23   | 17   |
+------+------+------+
| Bad  | 23   | 4    |
+------+------+------+

我只是在做一些功能, 产生其他的表语法, 比如“简单表格”或“多线表格”(见Pandocs readme)。


P. S.: you could also export this table easily to HTML (besides other formats like docx, odt etc.) with the (not yet documented) Pandoc reference class like:

> myReport <- Pandoc$new()
> myReport$add(x)
> myReport

Anonymous s report
==================
 written by *Anonymous* at *Sun May 27 21:04:22 2012*

  This report holds 1 block(s). 

---

+------+------+------+
|      | M    | F    |
+------+------+------+
| Good | 23   | 17   |
+------+------+------+
| Bad  | 23   | 4    |
+------+------+------+


---

Proc. time:  0.009 seconds. 

> myReport$format <-  html 
> myReport$export()

Exported to */tmp/pander-4e9c12ff63a6.[md|html]* under 0.031 seconds.

P.S.第二:您也可以 < a href=" http://cran.r-project.org/web/packages/brew/index.html" rel="noreferr"\\code>brew (类似 sweave) 一份包含 Pandoc.brew 的文本文件, 它会自动转换您的

> t <-  # Title
+ 
+ A nice matrix:
+ 
+ <%=matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE)%>
+ 
+ Bye-bye! 
> 
> Pandoc.brew(text=t)
# Title

A nice matrix:

+------+------+------+
|      | M    | F    |
+------+------+------+
| Good | 23   | 17   |
+------+------+------+
| Bad  | 23   | 4    |
+------+------+------+

Bye-bye!
问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签