Learn R Programming

sjPlot (version 2.4.0)

sjt.df: Show (description of) data frame as HTML table

Description

Shows description or the content of data frame (rows and columns) as HTML table, or saves it as file. Helpful if you want a quick overview of a data frame's content. See argument describe for details. By default, describe is TRUE and a description of the data frame is given, using the describe-function of the psych-package.

Usage

sjt.df(mydf, describe = TRUE, altr.row.col = FALSE, sort.col = NULL,
  sort.asc = TRUE, title = NULL, repeat.header = FALSE,
  show.type = FALSE, show.rownames = TRUE, show.cmmn.row = FALSE,
  string.cmmn = "No comment...", string.var = "Variable", big.mark = NULL,
  hide.progress = FALSE, CSS = NULL, encoding = NULL, file = NULL,
  use.viewer = TRUE, no.output = FALSE, remove.spaces = TRUE, ...)

Arguments

mydf

data frame that should be printed as table

describe

logical, if TRUE (default), a description of the data frame's variables is given. The description is retrieved from the describe function. If describe = FALSE, the data frame's content (values) is shown.

altr.row.col

Logical, if TRUE, alternating rows are highlighted with a light gray background color.

sort.col

indicates a column, either by column name or by column index number, that should be sorted. Default order is ascending, which can be changed with sort.asc argument. Default is NULL, hence the data frame is printed with no specific order. See 'Examples'.

sort.asc

logical, if TRUE (default) and sort.col is not NULL, data frame is ordered according to the specified column in an ascending order. Use FALSE to apply descending order. See 'Examples'.

title

Table caption, as character vector.

repeat.header

logical, if TRUE, the header row will also be added at the bottom at the table. This might be helpful, if you have longer tables and want to see the column names at the end of the table as well.

show.type

logical, if TRUE, the variable type is shown in a separate row respectively column.

show.rownames

logical, if TRUE and describe = FALSE, first table column contains row names of data frame. Use show.rownames = FALSE to omit first table column with row names.

show.cmmn.row

logical, if TRUE, an optional comment line can be added to the end / below the table. Use string.cmmn to specify the comment.

string.cmmn

string that will be added to the end / below the table. Only applies, if show.cmmn.row = TRUE.

string.var

string, label used for the first column name. Default is "Variable".

big.mark

character; if not NULL, used as mark between every thousands decimals before (hence big) the decimal point

hide.progress

logical, if TRUE, the progress bar that is displayed when creating the output is hidden. Default in FALSE, hence the bar is visible.

CSS

A list with user-defined style-sheet-definitions, according to the official CSS syntax. For more details, see this package-vignette, or 'Details' in sjt.frq.

encoding

String, indicating the charset encoding used for variable and value labels. Default is NULL, so encoding will be auto-detected depending on your platform (e.g., "UTF-8" for Unix and "Windows-1252" for Windows OS). Change encoding if specific chars are not properly displayed (e.g. German umlauts).

file

Destination file, if the output should be saved as file. If NULL (default), the output will be saved as temporary file and openend either in the IDE's viewer pane or the default web browser.

use.viewer

Logical, if TRUE, the HTML table is shown in the IDE's viewer pane. If FALSE or no viewer available, the HTML table is opened in a web browser.

no.output

Logical, if TRUE, the html-output is neither opened in a browser nor shown in the viewer pane and not even saved to file. This option is useful when the html output should be used in knitr documents. The html output can be accessed via the return value.

remove.spaces

Logical, if TRUE, leading spaces are removed from all lines in the final string that contains the html-data. Use this, if you want to remove parantheses for html-tags. The html-source may look less pretty, but it may help when exporting html-tables to office tools.

...

other arguments passed down to the describe function.

Value

Invisibly returns

  • the data frame with the description information (data),

  • the web page style sheet (page.style),

  • the web page content (page.content),

  • the complete html-output (output.complete) and

  • the html-table with inline-css for use with knitr (knitr)

for further use.

Details

See 'Details' in sjt.frq.

See Also

Examples

Run this code
# NOT RUN {
# init dataset
library(sjmisc)
data(efc)

# plot efc-data frame summary
sjt.df(efc, altr.row.col = TRUE)

# plot content, first 50 rows of first 5 columns of example data set
sjt.df(efc[1:50, 1:5], describe = FALSE, string.var = "Observation")

# plot efc-data frame summary, sorted descending by mean-column
sjt.df(efc, sort.col = "mean", sort.asc = FALSE)

# plot first 20 rows of first 5 columns of example data set,
# sort by column "e42dep" with alternating row colors
sjt.df(efc[1:20, 1:5], altr.row.col = TRUE,
       sort.col = "e42dep", describe = FALSE)

# plot first 20 rows of first 5 columns of example data set,
# sorted by 4th column in descending order.
sjt.df(efc[1:20, 1:5], sort.col = 4, sort.asc = FALSE, describe = FALSE)

# add big mark to thousands
library(datasets)
sjt.df(as.data.frame(WorldPhones), big.mark = ",")

# User defined style sheet
sjt.df(efc, altr.row.col = TRUE,
       CSS = list(css.table = "border: 2px solid #999999;",
                  css.tdata = "border-top: 1px solid;",
                  css.arc = "color:blue;"))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab