Learn R Programming

fdth (version 1.2-1)

latex.fdt: LaTeX table of the frequency distribution table

Description

This function returns a LaTeX table of the fdt objects.

Usage

latex.fdt(x, columns=1:6, round=2, format.classes=TRUE, pattern='%.2f', replace.breaks=TRUE, where='!tbp', caption=NULL, label=NULL, size='', algtable=c('\\flushleft', '\\centering', '\\flushright'), hline1='\\hline', header=NULL, hline2='\\hline', algclim='l', algfreq='r', hline3='\\hline')
latex.fdt_cat(x, columns=1:6, where='!tbp', caption=NULL, label=NULL, size='', algtable=c('\\flushleft', '\\centering', '\\flushright'), hline1='\\hline', header=NULL, hline2='\\hline', algclim='l', algfreq='r', hline3='\\hline')
latex.fdt_cat.multiple(x, columns=1:6, where='!tbp', caption=NULL, label=NULL, size='', algtable=c('\\flushleft', '\\centering', '\\flushright'), hline1='\\hline', header=NULL, hline2='\\hline', algclim='l', algfreq='r', hline3='\\hline')

Arguments

x
A fdt object.
columns
A vector of integers to select columns of the data.frame table. For example: columns=c(1:2, 4, 6).
round
Rounds the fdt columns to the specified number of decimal places. The default is 2.
format.classes
Logical, if TRUE, the default, the first column of the data.frame table will be formated using regular expression according with pattern argument.
pattern
Same as fmt in sprintf. The default is '%.2f'.
replace.breaks
Logical, if TRUE, the default, the mathematical symbols for breaks: [,) or (,], will be replaced by the LaTeX $\vdash$ or $\dashv$ symbols.
where
Specifies the location to which the floating body can move. The default is '!tbp'. Possible values are the tabular environment same, e.g., 'h', 'b' and 'p'.
caption
Is a legend of table. The default is NULL. If the table class is fdt_cat.multiple, the caption should be a vector.
label
A text string representing a symbolic label for the table for referencing in the LaTeX \label and \ref commands. label is useful in a Rnoweb document only if caption is also provided.
size
Specifies the font size of the table. The default is empty. The possible values are the same size used for letters in latex, e.g., '\\scriptsize', '\\large' and '\\LARGE'.
algtable
Specifies the alignment of the table on page. The default is '\\flushleft'. Possible values are: '\\flushleft', '\\centering' and '\\flushright'.
hline1
The line type of the table top. The default is '\\hline'.
header
An alternative vector of strings for table header.
hline2
The line type of the lower table header. The default is '\\hline'.
algclim
Specifies the alignment of the Class Limits. The default is 'l'. Possible others values are 'c' and 'r'.
algfreq
Specifies the alignment of the frequency columns. The default is 'r'. Possible others values are 'c' and 'l'.
hline3
The line type of the end table. The default is '\\hline'.

Value

An object of the class latex.fdt and latex.fdt_cat.

Details

The function latex.fdt was developed to make the life easier for those who whish to make latex tables with the results of the fdt function.

Some people could ask: why do not use the function latex of the package Hmisc or xtable of the xtable? Both latex and xtable functions are complex. Many parameters are required to build an adequate fdt table. It is not always intuitive to many users, discouraging them to use the latex or xtable functions to build fdt tables.

The function latex.fdt is extremely easy to use. Obviously, the function provides a default formatting according to what the authors think is the ideal for presentation in articles, reports, and others. If the user is not satisfied with the formatting provided by this function, the functions latex and xtable provides arguments that allow formatting the tables according to the user need.

It is possible to select what columns of the table (a data.frame) will be shown, as well as the pattern of the first column. The columns are:

  1. Class limits
  2. f - Absolute frequency
  3. rf - Relative frequency
  4. rf(%) - Relative frequency, %
  5. cf - Cumulative frequency
  6. cf(%) - Cumulative frequency, %

The available parameters offer an easy and powerful way to format the fdt for publications and other purposes.

See Also

fdt, latex, xtable

Examples

Run this code

library(fdth)

# +++++ Quantitative data

##Example 1: The simplest possible
t1 <- fdt(rnorm(n=1e3,
                mean=10,
                sd=2))

t1x <- latex.fdt(t1)

t1x


## Example 2
(t1x <- latex.fdt(t1,
                  replace.breaks=FALSE,
                  columns=c(1:2, 4, 6)))


## Example 3
t2 <- fdt(rnorm(n=1e3,
                mean=10,
                sd=2),
          right=TRUE)

t2x <- latex.fdt(t2,
                 algtable='\\centering',
                 caption='Frequency distribution table 2',
                 label='tbl-2',
                 pattern='%.1f')

t2x


## Example 4
t3 <- fdt(rnorm(n=1e3,
                mean=10,
                sd=2))

t3x <- latex.fdt(t3,
                 algtable='\\flushright',
                 caption='Frequency distribution table 3',
                 label='tbl-3',
                 pattern='%.1e')

t3x

# +++++ Qualitative data

## Example 5
t4 <- fdt_cat(sample(LETTERS[1:3], 
                     replace=TRUE,
                     size=30))

t4x <- latex.fdt_cat(t4,
                     caption='Frequency distribution table 4',
                     label='tbl-4')
t4x

t5 <- fdt_cat(data.frame(c1=sample(LETTERS[1:3],
                                   replace=TRUE,
                                   size=10),
                         c2=sample(letters[4:5],
                                   replace=TRUE,
                                   size=10)))

caption <- c('Frequency distribution table 5',
             'Frequency distribution table 6')

t5x <- latex.fdt_cat.multiple(t5,
                              caption=caption,
                              algtable='\\flushleft')
t5x

Run the code above in your browser using DataLab