Is it possible to span a heading across 开发者_StackOverflowmultiple columns with hwrite (or any other HTML-creating package)? I can sort of fake it with dataframe pieces nested within a larger table, but it's not quite a real span (and it looks ugly).
I did not see a version of this in the examples but maybe there exists elsewhere.
Thanks, Tom
Edit: I should add that the print.xtable
method does html, also (I shouldn't assume that is known). Use the type = "html"
option.
No experience with html, but I do the following with LaTeX.
In the xtable
package, the print.xtable
method has an option add.to.row
that allows you to do just that. For add.to.row
you add a list-of-lists, where the first list is a list of row numbers and the second list is a list of commands to insert at that spot. From the ?print.xtable
:
add.to.row
-- a list of two components. The first component (which should be called 'pos') is a list contains the position of rows on which extra commands should be added at the end, The second component (which should be called 'command') is a character vector of the same length of the first component which contains the command that should be added at the end of the specified rows. Default value is NULL, i.e. do not add commands.
For LaTeX I use the following homemade command that add a "(1)" above the coefficient and t-stat column.
my.add.to.row <- function(x) {
first <- "\\hline \\multicolumn{1}{c}{} & "
middle <- paste(paste("\\multicolumn{2}{c}{(", seq(x), ")}", sep = ""), collapse = " & ")
last <- paste("\\\\ \\cline {", 2, "-", 1 + 2 * x, "}", collapse = "")
string <- paste(first, middle, last, collapse = "")
list(pos = list(-1), command = string)
}
HTH.
I can't see an obvious way of generating a table with headers that cross multiple columns. Here's a really awful hack that might solve your problem though.
Generate your table as normal.
In the source code for that page, the first row of the table will look something like
<td someattribute="somevalue">First column name</td><td someattribute="somevalue">Second column name</td>
You can read the file into R, either with
htmlTreeParse
from theXML
package, or plain oldreadLines
.Now replace the offending bit of html with the correct value. The
stringr
package may well help here.<td someattribute="somevalue" colspan="2">Column name spanning two columns</td>
And write back out to file.
精彩评论