Create LaTeX Mathematical Array
xtableMatharray.RdConvert an array of numbers or mathematical expressions into an
xtableMatharray object so it can be printed. A convenience
function to enable the printing of arrays in mathematical expressions
in LaTeX.
Usage
xtableMatharray(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, auto = FALSE, ...)Arguments
- x
A numeric or character matrix.
- caption
Character vector of length 1 or 2 containing the table's caption or title. If length is 2, the second item is the "short caption" used when LaTeX generates a "List of Tables". Set to
NULLto suppress the caption. Default value isNULL. Included here only for consistency withxtablemethods. Not expected to be of use.- label
Character vector of length 1 containing the LaTeX label. Set to
NULLto suppress the label. Default value isNULL.- align
Character vector of length equal to the number of columns of the resulting table, indicating the alignment of the corresponding columns. Also,
"|"may be used to produce vertical lines between columns in LaTeX tables, but these are effectively ignored when considering the required length of the supplied vector. If a character vector of length one is supplied, it is split asstrsplit(align, "")[[1]]before processing. Since the row names are printed in the first column, the length ofalignis one greater thanncol(x)ifxis adata.frame. Use"l","r", and"c"to denote left, right, and center alignment, respectively. Use"p{3cm}"etc. for a LaTeX column of the specified width. For HTML output the"p"alignment is interpreted as"l", ignoring the width request. Default depends on the class ofx.- digits
Numeric vector of length equal to one (in which case it will be replicated as necessary) or to the number of columns of the resulting table or matrix of the same size as the resulting table, indicating the number of digits to display in the corresponding columns. Since the row names are printed in the first column, the length of the vector
digitsor the number of columns of the matrixdigitsis one greater thanncol(x)ifxis adata.frame. Default depends on the class ofx. If values ofdigitsare negative, the corresponding values ofxare displayed in scientific format withabs(digits)digits.- display
Character vector of length equal to the number of columns of the resulting table, indicating the format for the corresponding columns. Since the row names are printed in the first column, the length of
displayis one greater thanncol(x)ifxis adata.frame. These values are passed to theformatCfunction. Use"d"(for integers),"f","e","E","g","G","fg"(for reals), or"s"(for strings)."f"gives numbers in the usualxxx.xxxformat;"e"and"E"given.ddde+nnorn.dddE+nn(scientific format);"g"and"G"putx[i]into scientific format only if it saves space to do so."fg"uses fixed format as"f", butdigitsas number of significant digits. Note that this can lead to quite long result strings. Default depends on the class ofx.- auto
Logical, indicating whether to apply automatic format when no value is passed to
align,digits, ordisplay. This ‘autoformat’ (based onxalign,xdigits, andxdisplay) can be useful to quickly format a typicalmatrixordata.frame. Default value isFALSE.- ...
Additional arguments. (Currently ignored.)
Details
This function is only usable for production of LaTeX documents, not HTML.
Creates an object of class
c("xtableMatharray","xtable","data.frame"), to ensure that it is
printed by the print method print.xtableMatharray.
Examples
V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05,
3.010497e-05, 3.320683e-04, -5.284854e-05,
7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3)
mth <- xtableMatharray(V)
class(mth)
#> [1] "xtableMatharray" "xtable" "data.frame"
str(mth)
#> Classes ‘xtableMatharray’, ‘xtable’ and 'data.frame': 3 obs. of 3 variables:
#> $ 1: num 1.14e-03 3.01e-05 7.33e-05
#> $ 2: num 3.01e-05 3.32e-04 -5.28e-05
#> $ 3: num 7.33e-05 -5.28e-05 3.52e-04
#> - attr(*, "align")= chr [1:4] "r" "r" "r" "r"
#> - attr(*, "digits")= num [1:4] 0 2 2 2
#> - attr(*, "display")= chr [1:4] "s" "f" "f" "f"
unclass(mth)
#> $`1`
#> [1] 1.140380e-03 3.010497e-05 7.334879e-05
#>
#> $`2`
#> [1] 3.010497e-05 3.320683e-04 -5.284854e-05
#>
#> $`3`
#> [1] 7.334879e-05 -5.284854e-05 3.520928e-04
#>
#> attr(,"row.names")
#> [1] 1 2 3
#> attr(,"align")
#> [1] "r" "r" "r" "r"
#> attr(,"digits")
#> [1] 0 2 2 2
#> attr(,"display")
#> [1] "s" "f" "f" "f"