\alias{xdisplay}
\title{Suggest Appropriate Formatting}
\description{
- Suggest an appropriate \code{xtable} alignment, appropriate number of
- digits, or display type for a vector, or each column of a matrix or
- data frame.
+ Suggest an appropriate alignment, number of digits, and display type
+ for \code{xtable}.
}
\usage{
xalign(x, pad = TRUE)
}
\arguments{
\item{x}{a vector, matrix, or data frame.}
- \item{pad}{when \code{x} is two-dimensional, \code{pad = TRUE} inserts
- an extra code for the row names: \code{"l"} alignment , \code{0}
- digits, and \code{"s"} display.}
+ \item{pad}{whether to format row names, when \code{x} is
+ two-dimensional.}
\item{zap}{the number of digits passed to \code{zapsmall}.}
}
\value{
- A character or a vector of characters, specifying the suggested
- alignment, number of digits, or display type.
+ \code{xalign} returns a character vector consisting of \code{"l"} and
+ \code{"r"} elements, for left/right alignment.
+
+ \code{xdigits} returns an integer vector.
+
+ \code{xdisplay} returns a character vector of \code{"d"}, \code{"f"},
+ and \code{"s"} elements, for integer/double/string display.
}
\author{Arni Magnusson.}
\seealso{
- \code{\link{xtable}}.
+ \code{\link{xtable}}, \code{\link{align}}, \code{\link{digits}},
+ \code{\link{display}}
}
\examples{
## Vector
## Data frame
head(mtcars)
-xalign(mtcars, pad = FALSE)
-xalign(mtcars, pad = TRUE)
-xtable(mtcars, align = xalign(mtcars))
-
xdigits(mtcars, pad = FALSE)
xdigits(mtcars, pad = TRUE)
-xtable(mtcars, digits = xdigits(mtcars))
+xalign(mtcars)
+xdisplay(mtcars)
-xdisplay(mtcars, pad = FALSE)
-xdisplay(mtcars, pad = TRUE)
-xtable(mtcars, display = xdisplay(mtcars))
+## Autoformat when xtable is created
+xtable(mtcars, align = xalign(mtcars), digits = xdigits(mtcars),
+ display = xdisplay(mtcars))
-## Postprocessing an xtable
-state <- xtable(state.x77)
-align(state) <- xalign(state)
-digits(state) <- xdigits(state)
-display(state) <- xdisplay(state)
+## Autoformat existing xtable
+mt <- xtable(mtcars)
+align(mt) <- xalign(mt)
+digits(mt) <- xdigits(mt)
+display(mt) <- xdisplay(mt)
}
\keyword{array}
\keyword{print}
\alias{xtable.zoo}
\title{Create Export Tables}
\description{
- Function converting an R object to an \code{xtable} object, which can
+ Convert an R object to an \code{xtable} object, which can
then be printed as a LaTeX or HTML table.
}
\usage{
depends on the class of \code{x}. For example, \code{aov} objects
produce ANOVA tables while \code{data.frame} objects produce a table
of the entire data frame. One can optionally provide a caption
- (called a title in HTML) or label (called an anchor in HTML), as well
+ or label (called an anchor in HTML), as well
as formatting specifications. Default values for \code{align},
\code{digits}, and \code{display} are class dependent.
attributes \code{align}, \code{digits}, and \code{display}. It is
strongly recommened that you set these attributes through the provided
replacement functions as they perform validity checks.
- }
- \value{An object of class \code{"xtable"} which inherits the
+}
+\value{An object of class \code{"xtable"} which inherits the
\code{data.frame} class and contains several additional attributes
specifying the table formatting options.
}
\author{David Dahl \email{dahl@stat.byu.edu} with contributions and
suggestions from many others (see source code).
}
-\seealso{\code{\link{print.xtable}}, \code{\link{caption}},
+\seealso{
+ \code{\link{print.xtable}}, \code{\link{caption}},
\code{\link{label}}, \code{\link{align}}, \code{\link{digits}},
- \code{\link{display}}, \code{\link{formatC}}, \code{\link{methods}}
+ \code{\link{display}}
+
+ \code{\link{xalign}}, \code{\link{xdigits}}, \code{\link{xdisplay}}
}
\examples{
## Demonstrate data.frame
tli.table <- xtable(tli[1:20, ])
-digits(tli.table)[c(2, 6)] <- 0
print(tli.table)
print(tli.table, type = "html")
## Demonstrate data.frame with different digits in cells
tli.table <- xtable(tli[1:20, ])
-digits(tli.table) <- matrix( 0:4, nrow = 20, ncol = ncol(tli)+1 )
+display(tli.table)[c(2,6)] <- "f"
+digits(tli.table) <- matrix(0:4, nrow = 20, ncol = ncol(tli)+1)
print(tli.table)
print(tli.table, type = "html")