Skip to content

Instantly share code, notes, and snippets.

@dewittpe
Created June 11, 2014 05:07
Show Gist options
  • Save dewittpe/8a7bf780da05b5b0d25a to your computer and use it in GitHub Desktop.
Save dewittpe/8a7bf780da05b5b0d25a to your computer and use it in GitHub Desktop.
Example of a table with two header rows and one spanning multiple columns
<!DOCTYPE html>
<html>
<head>
<title>Example of a table with two header rows and one spanning multiple columns</title>
</head>
<body>
<h1> Example of a table with two header rows - year spanning two columns (n and %). </h1>
Create a silly example table:
<!--begin.rcode
tab <- table(mtcars$cyl)
tab <- cbind(tab, paste0("(", round(prop.table(tab)*100, 1), ")"))
tab <- cbind(tab, tab)
colnames(tab) <- rep(c("n", "(%)"), 2)
rownames(tab) <- paste(rownames(tab), "cly")
end.rcode-->
Create the html code here as follows and the table is below. The Gmisc package is helpful.
<!--begin.rcode, results = 'asis'
library(Gmisc)
temp <- htmlTable(tab, file = "exampleTable.tex", append = TRUE, title = "",
cgroup = c("Year 1", "Year 2"), n.cgroup = c(2, 2))
cat(temp)
end.rcode-->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment