Description Usage Arguments Value Author(s) See Also Examples
This function coverts a character matrix to an html table.
1 |
x |
a character matrix. Is most of the cases it is the object
returned by |
caption |
a string to be the caption of the table. Default is
|
styles |
a vector with style definition for |
indexes |
a positive integer matrix with dimensions equal to
|
class |
a string corresponding a table style defined in a
|
a character vector. Use cat
inside chunks with header
results = "asis"
to print the result as interpretable code
of an html table.
Walmes Zeviani, walmes@ufpr.br.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | x <- head(rock)
x <- sapply(x, as.character)
str(x)
m2h <- matrix2html(x)
cat(m2h)
x <- mtcars[1:10, 1:3]
x <- rbind(c("", colnames(x)), cbind(rownames(x), x))
x <- as.matrix(x)
rownames(x) <- colnames(x) <- NULL
x[1,1] <- "Cars"
x
m2h <- matrix2html(x, caption="Part of the cars data set.")
cat(m2h)
# These table class are assumed to be defined in a css file as
# follow.
# td.red { color: #CC0000; }
# td.blue { color: #0000CC; }
# td.shade { background-color: #CCCCCC; }
# td.line { border-bottom: 1px solid #000000; }
# td.bold { font-weight: bold; }
# td.italic { font-style: italic; }
sty <- c("<th align=\"center\">%s</th>", "<tr>\n%s\n</tr>\n",
"<td align=\"center\">%s</td>",
"<td align=\"center\" class=\"red\">%s</td>",
"<td align=\"center\" class=\"blue line\">%s</td>",
"<td align=\"center\" class=\"shade\">%s</td>",
"<td align=\"center\" class=\"line\">%s</td>",
"<td align=\"center\" class=\"bold shade\">%s</td>",
"<td align=\"center\" class=\"italic blue\">%s</td>")
# Which style for which cell table.
idx <- 0L * row(x) + 3L
idx[3, ] <- 4L
idx[4, ] <- 5L
idx[5, ] <- 6L
idx[7, ] <- 7L
idx[8, ] <- 8L
idx[9, ] <- 9L
idx[, 3] <- 3L
idx[1, ] <- 1L
m2h <- matrix2html(x = x, styles = sty, indexes = idx,
caption = "Part of the cars data set.")
cat(m2h)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.