| percents | R Documentation |
Calculate percentages in a table. rowPercent gives row percentages,
colPercent gives column percentages, and rowColPercent gives
both row and column percentages.
colPercent(t, pretty.text = FALSE, keep = TRUE, digits = 4)
rowPercent(t, pretty.text = FALSE, keep = TRUE, digits = 4)
rowColPercent(t, keep = TRUE, ...)
colPercentAsHTML(
t,
keep = TRUE,
row.names = NULL,
column.names = NULL,
html.table.border = 0,
banded.rows = FALSE,
col.odd = "none",
col.even = "lightgrey",
caption = NA,
transpose = FALSE,
...
)
rowPercentAsHTML(
t,
keep = TRUE,
row.names = NULL,
column.names = NULL,
html.table.border = 0,
banded.rows = FALSE,
col.odd = "none",
col.even = "lightgrey",
caption = NA,
transpose = FALSE,
...
)
rowColPercentAsHTML(
t,
keep = TRUE,
row.names = NULL,
column.names = NULL,
html.table.border = 0,
banded.rows = FALSE,
col.odd = "none",
col.even = "lightgrey",
caption = NA,
...
)
t |
a matrix |
pretty.text |
logical; if |
keep |
logical; if |
digits |
number of digits to round to |
... |
additional arguments from |
row.names |
(optional) vector of row names in table |
column.names |
(optional) vector of column names in table |
html.table.border |
border type for the table. Defaults to 0 in HTML syntax. |
banded.rows |
logical; if |
col.odd |
colour to use for odd numbered rows |
col.even |
colour to use for even numbered rows |
caption |
table caption. Uses |
transpose |
logical; if |
Generates a table of row and/or column percentages given table t.
Using pretty.text = TRUE will add the \
Row and column names can be replaced by row.names and
column.names. Higher values of html.table.border make the table
borders thicker and even look 3D. col.odd and col.even are
ignored when banded.rows = FALSE.
Transposing is useful if there are many columns in a single row or vice versa. Note that the percentages are unchanged, only the orientation of the table.
A table with row-wise/column-wise percentages added. The percentages sum to 1 per row/column.
HTML-based functions return the code used to generate a table that shows row and/or column percentages.
Aline Talhouk, Samuel Leung, Derek Chiu
# Base outputs
A <- matrix(c(2, 3, 5, 10), nrow = 2, dimnames = list(c("Row1", "Row2"), c("Col1", "Col2")))
rowPercent(A)
rowPercent(A, keep = FALSE)
colPercent(A, pretty.text = TRUE)
colPercent(A, pretty.text = TRUE, keep = FALSE)
rowColPercent(A, digits = 2)
# HTML outputs
library(htmlTable)
set.seed(13)
B <- matrix(rbinom(16, size = 20, prob = 0.3), nrow = 4,
dimnames = list(paste0("Row", 1:4), paste0("Col", 1:4)))
htmlTable(rowColPercentAsHTML(B, keep = TRUE, digits = 2, pretty.text = TRUE,
banded.rows = TRUE, col.odd = "yellow", col.even = "green", caption =
"Example Table", html.table.border = 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.