Learn R Programming

sjPlot (version 1.8.1)

view_df: View structure of labelled data frames

Description

Save (or show) content of an imported SPSS, SAS or Stata data file, or any similar labelled data.frame, as HTML table. Similar to the SPSS variable view. This quick overview shows variable ID numner, name, label, type and associated value labels. The result can be considered as "codeplan" of the data frame.

Usage

view_df(x, weightBy = NULL, file = NULL, alternateRowColors = TRUE,
  showID = TRUE, showType = FALSE, showValues = TRUE,
  showValueLabels = TRUE, showFreq = FALSE, showPerc = FALSE,
  showWtdFreq = FALSE, showWtdPerc = FALSE, sortByName = FALSE,
  breakVariableNamesAt = 50, encoding = NULL, hideProgressBar = FALSE,
  CSS = NULL, useViewer = TRUE, no.output = FALSE, remove.spaces = TRUE)

Arguments

x
data.frame, imported by read_spss, read_sas or read_stata function, or
weightBy
weight factor that will be applied to weight all cases from data. Must be a vector of same length as nrow(data). Default is NULL, so no weights are used.
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.
alternateRowColors
logical, if TRUE, alternating rows are highlighted with a light gray background color.
showID
logical, if TRUE (default), the variable ID is shown in the first column.
showType
logical, if TRUE, the variable type is shown in a separate column. Since SPSS variable types are mostly numeric after import, this column is hidden by default.
showValues
logical, if TRUE (default), the variable values are shown as additional column.
showValueLabels
logical, if TRUE (default), the value labels are shown as additional column.
showFreq
logical, if TRUE, an additional column with frequencies for each variable is shown.
showPerc
logical, if TRUE, an additional column with percentage of frequencies for each variable is shown.
showWtdFreq
logical, if TRUE, an additional column with weighted frequencies for each variable is shown. Weights strem from weightBy.
showWtdPerc
logical, if TRUE, an additional column with weighted percentage of frequencies for each variable is shown. Weights strem from weightBy.
sortByName
logical, if TRUE, rows are sorted according to the variable names. By default, rows (variables) are ordered according to their order in the data frame.
breakVariableNamesAt
Wordwrap for lomg variable names. Determines how many chars of a variable name are displayed in one line and when a line break is inserted. Default value is 50, use NULL to turn off word wrap.
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). Ch
hideProgressBar
If TRUE, the progress bar that is displayed when creating the table is hidden. Default in FALSE, hence the bar is visible.
CSS
list-object with user-defined style-sheet-definitions, according to the http://www.w3.org/Style/CSS/{official CSS syntax}. See 'Details'.
useViewer
If TRUE, the function tries to show the HTML table 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 access
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-

Value

  • Invisibly returns
    • 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

  • http://www.strengejacke.de/sjPlot/datainit/{sjPlot manual: data initialization}
  • http://www.strengejacke.de/sjPlot/view_spss/{sjPlot manual: inspecting (SPSS imported) data frames}

Examples

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

# view variables
view_df(efc)

# view variables w/o values and value labels
view_df(efc, showValues = FALSE, showValueLabels = FALSE)

# view variables including variable typed, orderd by name
view_df(efc, sortByName = TRUE, showType = TRUE)

# ----------------------------------------------------------------
# User defined style sheet
# ----------------------------------------------------------------
view_df(efc,
        CSS = list(css.table = "border: 2px solid;",
                   css.tdata = "border: 1px solid;",
                   css.arc = "color:blue;"))

Run the code above in your browser using DataLab