This function will output a descriptive variable table either to the console or as an HTML file that can be viewed continuously while working with data. vt()
is the same thing but requires fewer key presses to type.
vtable(
data,
out = NA,
file = NA,
labels = NA,
class = TRUE,
values = TRUE,
missing = FALSE,
index = FALSE,
factor.limit = 5,
char.values = FALSE,
data.title = NA,
desc = NA,
note = NA,
note.align = "l",
anchor = NA,
col.width = NA,
col.align = NA,
align = NA,
fit.page = NA,
summ = NA,
lush = FALSE,
opts = list()
)
vt(
data,
out = NA,
file = NA,
labels = NA,
class = TRUE,
values = TRUE,
missing = FALSE,
index = FALSE,
factor.limit = 5,
char.values = FALSE,
data.title = NA,
desc = NA,
note = NA,
note.align = "l",
anchor = NA,
col.width = NA,
col.align = NA,
align = NA,
fit.page = NA,
summ = NA,
lush = FALSE,
opts = list()
)
Data set; accepts any format with column names. If variable labels are set with the haven package, set_label()
from sjlabelled, or label()
from Hmisc, vtable
will extract them automatically.
Determines where the completed table is sent. Set to "browser"
to open HTML file in browser using browseURL()
, "viewer"
to open in RStudio viewer using viewer()
, if available. Use "htmlreturn"
to return the HTML code to R. Use "return"
to return the completed variable table to R in data frame form or "kable"
to return it as a knitr::kable()
. Additional options include "csv"
to write to CSV in conjunction with file
(although this will drop most additional formatting), "latex"
for a LaTeX table or "latexpage"
for a full buildable LaTeX page. Defaults to "viewer"
if RStudio is running, "browser"
if it isn't, or a "kable"
passed through kableExtra::kable_styling()
defaults if it's an RMarkdown document being built with knitr
.
Saves the completed variable table file to HTML or .tex with this filepath. May be combined with any value of out
, although note that out = "return"
and out = "kable"
will still save the standard vtable HTML file as with out = "viewer"
or out = "browser"
.
Variable labels. labels will accept three formats: (1) A vector of the same length as the number of variables in the data, in the same order as the variables in the data set, (2) A matrix or data frame with two columns and more than one row, where the first column contains variable names (in any order) and the second contains labels, or (3) A matrix or data frame where the column names (in any order) contain variable names and the first row contains labels. Setting the labels parameter will override any variable labels already in the data. Set to "omit"
if the data set has embedded labels but you don't want any labels in the table.
Set to TRUE
to include variable classes in the variable table. Defaults to TRUE
.
Set to TRUE
to include the range of values of each variable: min and max for numeric variables, list of factors for factor or ordered variables, and 'TRUE FALSE' for logicals. values will detect and use value labels set by the sjlabelled or haven packages, as long as every value is labelled. Defaults to TRUE
.
Set to TRUE
to include the number of NAs in the variable. Defaults to FALSE
.
Set to TRUE
to include the index number of the column with the variable name. Defaults to FALSE
.
Sets maximum number of factors that will be included if values = TRUE
. Set to 0 for no limit. Defaults to 5.
Set to TRUE
to include values of character variables as though they were factors, if values = TRUE
. Or, set to a character vector of variable names to list values of only those character variables. Defaults to FALSE
. Has no effect if values = FALSE
.
Character variable with the title of the dataset.
Character variable offering a brief description of the dataset itself. This will by default include information on the number of observations and the number of columns. To remove this, set desc='omit'
, or include any description and then include 'omit'
as the last four characters.
Table note to go after the last row of the table.
Set the alignment for the multi-column table note. Usually "l", but if you have a long note in LaTeX you might want to set it with "p"
Character variable to be used to set an anchor link in HTML tables, or a label tag in LaTeX.
Vector of page-width percentages, on 0-100 scale, overriding default column widths in HTML table. Must have a number of elements equal to the number of columns in the resulting table.
For HTML output, a character vector indicating the HTML text-align
attributes to be used in the table (for example col.align = c('left','center','center')
. Defaults to all left-aligned. If you want to get tricky, you can add a ";"
afterwards and keep putting in whatever CSS attributes you want. They will be applied to the whole column.
For LaTeX output, string indicating the alignment of each column. Use standard LaTeX syntax (i.e. l|ccc
). Defaults to all p{}
columns with widths set using the same defaults as with col.width
. Be sure to escape special characters, in particular backslashes (i.e. p{.25\\textwidth}
instead of p{.25\textwidth}
).
For LaTeX output, uses a resizebox to force the table to a certain width. Set to NA
to omit. Often '\textwidth'
.
Character vector of summary statistics to include for numeric and logical variables, in the form 'function(x)'
. This option is flexible, and allows any summary statistic function that takes in a column and returns a single number. For example, summ=c('mean(x)','mean(log(x))')
will provide the mean of each variable as well as the mean of the log of each variable. Keep in mind the special vtable package helper functions designed specifically for this option propNA
, countNA
, and notNA
, which report counts and proportions of NAs, or counts of not-NAs, in the vectors, nuniq
, which reports the number of unique values, and pctile
, which returns a vector of the 100 percentiles of the variable. NAs will be omitted from all calculations other than propNA(x)
and countNA(x)
.
Set to TRUE
to select a set of options with more information: sets char.values
and missing
to TRUE
, and sets summ to c('mean(x)', 'sd(x)', 'nuniq(x)')
. summ
can be overwritten by setting summ
to something else.
The same vtable
options as above, but in a named list format. Useful for applying the same set of options to multiple vtable
s.
Outputting the variable table as a help file will make it easy to search through variable names or labels, or to refer to information about the variables easily.
This function is in a similar spirit to promptData()
, but focuses on variable documentation rather than dataset documentation.
If you would like to include a vtable
in an RMarkdown document, it should just work! If you leave out
blank, it will default to a nicely-formatted knitr::kable()
, although this will drop some formatting elements like multi-column cells (or do out="kable"
to get an unformatted kable
that you can format yourself). If you prefer the vtable
package formatting, then use out="latex"
if outputting to LaTeX or out="htmlreturn"
for HTML, both with results="asis"
in the code chunk. Alternately, in HTML, you can use the file
option to write to file and use a <iframe>
to include it.
#>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>df</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> df </h1><p>This data contains 4 rows and 5 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:22%; text-align:left">Name</th><th style = "width:11%; text-align:left">Class</th><th style = "width:39%; text-align:left">Label</th><th style = "width:28%; text-align:left">Values</th></tr>
#> <tr><td style = "width:22%; text-align:left">var1</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 1</td><td style = "width:28%; text-align:left">Num: 1 to 4</td></tr>
#> <tr><td style = "width:22%; text-align:left">var2</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 2</td><td style = "width:28%; text-align:left">Num: 5 to 8</td></tr>
#> <tr><td style = "width:22%; text-align:left">var3</td><td style = "width:11%; text-align:left">character</td><td style = "width:39%; text-align:left">Some Letters</td><td style = "width:28%; text-align:left"></td></tr>
#> <tr><td style = "width:22%; text-align:left">var4</td><td style = "width:11%; text-align:left">factor</td><td style = "width:39%; text-align:left">Some Labels</td><td style = "width:28%; text-align:left">'A' 'B' 'C'</td></tr>
#> <tr><td style = "width:22%; text-align:left">var5</td><td style = "width:11%; text-align:left">logical</td><td style = "width:39%; text-align:left">You Good?</td><td style = "width:28%; text-align:left">TRUE FALSE</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>subset(df, select = c(1, 2, 5))</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> subset(df, select = c(1, 2, 5)) </h1><p>This data contains 4 rows and 3 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:29%; text-align:left">Name</th><th style = "width:51%; text-align:left">Label</th></tr>
#> <tr><td style = "width:29%; text-align:left">var1</td><td style = "width:51%; text-align:left">Number 1</td></tr>
#> <tr><td style = "width:29%; text-align:left">var2</td><td style = "width:51%; text-align:left">Number 2</td></tr>
#> <tr><td style = "width:29%; text-align:left">var5</td><td style = "width:51%; text-align:left">You Good?</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>subset(df, select = c("var1", "var4"))</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> subset(df, select = c("var1", "var4")) </h1><p>This data contains 4 rows and 2 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:10%; text-align:left">Name</th><th style = "width:10%; text-align:left">Class</th><th style = "width:40%; text-align:left">Label</th><th style = "width:35%; text-align:left">Values</th></tr>
#> <tr><td style = "width:10%; text-align:left">var1</td><td style = "width:10%; text-align:left">integer</td><td style = "width:40%; text-align:left">Number 1</td><td style = "width:35%; text-align:left">Num: 1 to 4</td></tr>
#> <tr><td style = "width:10%; text-align:left">var4</td><td style = "width:10%; text-align:left">factor</td><td style = "width:40%; text-align:left">Some Labels</td><td style = "width:35%; text-align:left">'A' and 2 more</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>df</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> df </h1><p>This data contains 4 rows and 5 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:22%; text-align:left">Name</th><th style = "width:11%; text-align:left">Class</th><th style = "width:39%; text-align:left">Label</th><th style = "width:28%; text-align:left">Values</th></tr>
#> <tr><td style = "width:22%; text-align:left">var1</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 1</td><td style = "width:28%; text-align:left">Num: 1 to 4</td></tr>
#> <tr><td style = "width:22%; text-align:left">var2</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 2</td><td style = "width:28%; text-align:left">Num: 5 to 8</td></tr>
#> <tr><td style = "width:22%; text-align:left">var3</td><td style = "width:11%; text-align:left">character</td><td style = "width:39%; text-align:left">Some Letters</td><td style = "width:28%; text-align:left"></td></tr>
#> <tr><td style = "width:22%; text-align:left">var4</td><td style = "width:11%; text-align:left">factor</td><td style = "width:39%; text-align:left">Some Labels</td><td style = "width:28%; text-align:left">'A' 'B' 'C'</td></tr>
#> <tr><td style = "width:22%; text-align:left">var5</td><td style = "width:11%; text-align:left">logical</td><td style = "width:39%; text-align:left">You Good?</td><td style = "width:28%; text-align:left">TRUE FALSE</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>df</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> df </h1><p>This data contains 4 rows and 5 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:22%; text-align:left">Name</th><th style = "width:11%; text-align:left">Class</th><th style = "width:39%; text-align:left">Label</th><th style = "width:28%; text-align:left">Values</th></tr>
#> <tr><td style = "width:22%; text-align:left">var1</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 1</td><td style = "width:28%; text-align:left">Num: 1 to 4</td></tr>
#> <tr><td style = "width:22%; text-align:left">var2</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 2</td><td style = "width:28%; text-align:left">Num: 5 to 8</td></tr>
#> <tr><td style = "width:22%; text-align:left">var3</td><td style = "width:11%; text-align:left">character</td><td style = "width:39%; text-align:left">Some Letters</td><td style = "width:28%; text-align:left"></td></tr>
#> <tr><td style = "width:22%; text-align:left">var4</td><td style = "width:11%; text-align:left">factor</td><td style = "width:39%; text-align:left">Some Labels</td><td style = "width:28%; text-align:left">'A' 'B' 'C'</td></tr>
#> <tr><td style = "width:22%; text-align:left">var5</td><td style = "width:11%; text-align:left">logical</td><td style = "width:39%; text-align:left">You Good?</td><td style = "width:28%; text-align:left">TRUE FALSE</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>df</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> df </h1><p>This data contains 4 rows and 5 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:22%; text-align:left">Name</th><th style = "width:11%; text-align:left">Class</th><th style = "width:39%; text-align:left">Label</th><th style = "width:28%; text-align:left">Values</th></tr>
#> <tr><td style = "width:22%; text-align:left">var1</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 1</td><td style = "width:28%; text-align:left">'1: A little' '2: Some more' '3: Even more' '4: A lot'</td></tr>
#> <tr><td style = "width:22%; text-align:left">var2</td><td style = "width:11%; text-align:left">integer</td><td style = "width:39%; text-align:left">Number 2</td><td style = "width:28%; text-align:left">Num: 5 to 8</td></tr>
#> <tr><td style = "width:22%; text-align:left">var3</td><td style = "width:11%; text-align:left">character</td><td style = "width:39%; text-align:left">Some Letters</td><td style = "width:28%; text-align:left"></td></tr>
#> <tr><td style = "width:22%; text-align:left">var4</td><td style = "width:11%; text-align:left">factor</td><td style = "width:39%; text-align:left">Some Labels</td><td style = "width:28%; text-align:left">'A' 'B' 'C'</td></tr>
#> <tr><td style = "width:22%; text-align:left">var5</td><td style = "width:11%; text-align:left">logical</td><td style = "width:39%; text-align:left">You Good?</td><td style = "width:28%; text-align:left">TRUE FALSE</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>efc</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> efc </h1><p>This data contains 908 rows and 26 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:22%; text-align:left">Name</th><th style = "width:11%; text-align:left">Class</th><th style = "width:39%; text-align:left">Label</th><th style = "width:28%; text-align:left">Values</th></tr>
#> <tr><td style = "width:22%; text-align:left">c12hour</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">average number of hours of care per week</td><td style = "width:28%; text-align:left">Num: 4 to 168</td></tr>
#> <tr><td style = "width:22%; text-align:left">e15relat</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">relationship to elder</td><td style = "width:28%; text-align:left">'1: spouse/partner' '2: child' '3: sibling' '4: daughter or son -in-law' '5: ancle/aunt' and 3 more</td></tr>
#> <tr><td style = "width:22%; text-align:left">e16sex</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">elder's gender</td><td style = "width:28%; text-align:left">'1: male' '2: female'</td></tr>
#> <tr><td style = "width:22%; text-align:left">e17age</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">elder' age</td><td style = "width:28%; text-align:left">Num: 65 to 103</td></tr>
#> <tr><td style = "width:22%; text-align:left">e42dep</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">elder's dependency</td><td style = "width:28%; text-align:left">'1: independent' '2: slightly dependent' '3: moderately dependent' '4: severely dependent'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c82cop1</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">do you feel you cope well as caregiver?</td><td style = "width:28%; text-align:left">'1: never' '2: sometimes' '3: often' '4: always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c83cop2</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">do you find caregiving too demanding?</td><td style = "width:28%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c84cop3</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">does caregiving cause difficulties in your relationship with your friends?</td><td style = "width:28%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c85cop4</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">does caregiving have negative effect on your physical health?</td><td style = "width:28%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c86cop5</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">does caregiving cause difficulties in your relationship with your family?</td><td style = "width:28%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c87cop6</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">does caregiving cause financial difficulties?</td><td style = "width:28%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c88cop7</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">do you feel trapped in your role as caregiver?</td><td style = "width:28%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c89cop8</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">do you feel supported by friends/neighbours?</td><td style = "width:28%; text-align:left">'1: never' '2: sometimes' '3: often' '4: always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c90cop9</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">do you feel caregiving worthwhile?</td><td style = "width:28%; text-align:left">'1: never' '2: sometimes' '3: often' '4: always'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c160age</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">carer' age</td><td style = "width:28%; text-align:left">Num: 18 to 89</td></tr>
#> <tr><td style = "width:22%; text-align:left">c161sex</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">carer's gender</td><td style = "width:28%; text-align:left">'1: Male' '2: Female'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c172code</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">carer's level of education</td><td style = "width:28%; text-align:left">'1: low level of education' '2: intermediate level of education' '3: high level of education'</td></tr>
#> <tr><td style = "width:22%; text-align:left">c175empl</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">are you currently employed?</td><td style = "width:28%; text-align:left">'0: no' '1: yes'</td></tr>
#> <tr><td style = "width:22%; text-align:left">barthtot</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Total score BARTHEL INDEX</td><td style = "width:28%; text-align:left">Num: 0 to 100</td></tr>
#> <tr><td style = "width:22%; text-align:left">neg_c_7</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Negative impact with 7 items</td><td style = "width:28%; text-align:left">Num: 7 to 28</td></tr>
#> <tr><td style = "width:22%; text-align:left">pos_v_4</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Positive value with 4 items</td><td style = "width:28%; text-align:left">Num: 5 to 16</td></tr>
#> <tr><td style = "width:22%; text-align:left">quol_5</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Quality of life 5 items</td><td style = "width:28%; text-align:left">Num: 0 to 25</td></tr>
#> <tr><td style = "width:22%; text-align:left">resttotn</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Job restrictions</td><td style = "width:28%; text-align:left">Num: 0 to 4</td></tr>
#> <tr><td style = "width:22%; text-align:left">tot_sc_e</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Services for elderly</td><td style = "width:28%; text-align:left">Num: 0 to 9</td></tr>
#> <tr><td style = "width:22%; text-align:left">n4pstu</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Care level</td><td style = "width:28%; text-align:left">'0: No Care Level' '1: Care Level 1' '2: Care Level 2' '3: Care Level 3' '4: Care Level 3+'</td></tr>
#> <tr><td style = "width:22%; text-align:left">nur_pst</td><td style = "width:11%; text-align:left">numeric</td><td style = "width:39%; text-align:left">Care level</td><td style = "width:28%; text-align:left">'1: Care Level 1' '2: Care Level 2' '3: Care Level 3/3+'</td></tr>
#> </table></body></html>
#> <html style="font-family:Helvetica,Arial,Sans">
#> <head><title>efc</title><style type = "text/css">
#> p {
#> font-size:smaller;
#> }
#> table {
#> border: 0px;
#> border-collapse:collapse;
#> font-size:smaller;
#> table-layout:fixed;
#> margin-left:0%;
#> margin-right:auto;
#> }
#> .headtab {
#> width: 100%;
#> margin-left:auto;
#> margin-right:auto;
#> }
#> th {
#> background-color: #FFFFFF;
#> font-weight:bold;
#> text-align:left;
#> }
#> table tr:nth-child(odd) td {
#> background-color: #FFFFFF;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }
#> table tr:nth-child(even) td {
#> background-color: #D3D3D3;
#> padding:4px;
#> word-wrap: break-word;
#> word-break:break-all;
#> }</style></head><body> <table class="headtab"> <tr><td style="text-align:left">vtable {vtable}</td> <td style="text-align:right">Variable Documentation</td></tr></table> <h1> efc </h1><p>This data contains 908 rows and 26 columns.</p><h3>Variable Table</h3><table><tr><th style = "width:19%; text-align:left">Name</th><th style = "width:9%; text-align:left">Class</th><th style = "width:32%; text-align:left">Label</th><th style = "width:23%; text-align:left">Values</th><th style = "width:17%; text-align:left">Summary</th></tr>
#> <tr><td style = "width:19%; text-align:left">c12hour</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">average number of hours of care per week</td><td style = "width:23%; text-align:left">Num: 4 to 168</td><td style = "width:17%; text-align:left">propNA: 0.007<br/>mean: 42.399</td></tr>
#> <tr><td style = "width:19%; text-align:left">e15relat</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">relationship to elder</td><td style = "width:23%; text-align:left">'1: spouse/partner' '2: child' '3: sibling' '4: daughter or son -in-law' '5: ancle/aunt' and 3 more</td><td style = "width:17%; text-align:left">propNA: 0.008<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">e16sex</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">elder's gender</td><td style = "width:23%; text-align:left">'1: male' '2: female'</td><td style = "width:17%; text-align:left">propNA: 0.008<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">e17age</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">elder' age</td><td style = "width:23%; text-align:left">Num: 65 to 103</td><td style = "width:17%; text-align:left">propNA: 0.019<br/>mean: 79.121</td></tr>
#> <tr><td style = "width:19%; text-align:left">e42dep</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">elder's dependency</td><td style = "width:23%; text-align:left">'1: independent' '2: slightly dependent' '3: moderately dependent' '4: severely dependent'</td><td style = "width:17%; text-align:left">propNA: 0.008<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c82cop1</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">do you feel you cope well as caregiver?</td><td style = "width:23%; text-align:left">'1: never' '2: sometimes' '3: often' '4: always'</td><td style = "width:17%; text-align:left">propNA: 0.008<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c83cop2</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">do you find caregiving too demanding?</td><td style = "width:23%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td><td style = "width:17%; text-align:left">propNA: 0.007<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c84cop3</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">does caregiving cause difficulties in your relationship with your friends?</td><td style = "width:23%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td><td style = "width:17%; text-align:left">propNA: 0.007<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c85cop4</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">does caregiving have negative effect on your physical health?</td><td style = "width:23%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td><td style = "width:17%; text-align:left">propNA: 0.011<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c86cop5</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">does caregiving cause difficulties in your relationship with your family?</td><td style = "width:23%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td><td style = "width:17%; text-align:left">propNA: 0.007<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c87cop6</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">does caregiving cause financial difficulties?</td><td style = "width:23%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td><td style = "width:17%; text-align:left">propNA: 0.009<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c88cop7</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">do you feel trapped in your role as caregiver?</td><td style = "width:23%; text-align:left">'1: Never' '2: Sometimes' '3: Often' '4: Always'</td><td style = "width:17%; text-align:left">propNA: 0.009<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c89cop8</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">do you feel supported by friends/neighbours?</td><td style = "width:23%; text-align:left">'1: never' '2: sometimes' '3: often' '4: always'</td><td style = "width:17%; text-align:left">propNA: 0.008<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c90cop9</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">do you feel caregiving worthwhile?</td><td style = "width:23%; text-align:left">'1: never' '2: sometimes' '3: often' '4: always'</td><td style = "width:17%; text-align:left">propNA: 0.022<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c160age</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">carer' age</td><td style = "width:23%; text-align:left">Num: 18 to 89</td><td style = "width:17%; text-align:left">propNA: 0.008<br/>mean: 53.463</td></tr>
#> <tr><td style = "width:19%; text-align:left">c161sex</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">carer's gender</td><td style = "width:23%; text-align:left">'1: Male' '2: Female'</td><td style = "width:17%; text-align:left">propNA: 0.008<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c172code</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">carer's level of education</td><td style = "width:23%; text-align:left">'1: low level of education' '2: intermediate level of education' '3: high level of education'</td><td style = "width:17%; text-align:left">propNA: 0.073<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">c175empl</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">are you currently employed?</td><td style = "width:23%; text-align:left">'0: no' '1: yes'</td><td style = "width:17%; text-align:left">propNA: 0.007<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">barthtot</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Total score BARTHEL INDEX</td><td style = "width:23%; text-align:left">Num: 0 to 100</td><td style = "width:17%; text-align:left">propNA: 0.028<br/>mean: 64.547</td></tr>
#> <tr><td style = "width:19%; text-align:left">neg_c_7</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Negative impact with 7 items</td><td style = "width:23%; text-align:left">Num: 7 to 28</td><td style = "width:17%; text-align:left">propNA: 0.018<br/>mean: 11.85</td></tr>
#> <tr><td style = "width:19%; text-align:left">pos_v_4</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Positive value with 4 items</td><td style = "width:23%; text-align:left">Num: 5 to 16</td><td style = "width:17%; text-align:left">propNA: 0.03<br/>mean: 12.477</td></tr>
#> <tr><td style = "width:19%; text-align:left">quol_5</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Quality of life 5 items</td><td style = "width:23%; text-align:left">Num: 0 to 25</td><td style = "width:17%; text-align:left">propNA: 0.012<br/>mean: 14.369</td></tr>
#> <tr><td style = "width:19%; text-align:left">resttotn</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Job restrictions</td><td style = "width:23%; text-align:left">Num: 0 to 4</td><td style = "width:17%; text-align:left">propNA: 0<br/>mean: 0.329</td></tr>
#> <tr><td style = "width:19%; text-align:left">tot_sc_e</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Services for elderly</td><td style = "width:23%; text-align:left">Num: 0 to 9</td><td style = "width:17%; text-align:left">propNA: 0<br/>mean: 1.014</td></tr>
#> <tr><td style = "width:19%; text-align:left">n4pstu</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Care level</td><td style = "width:23%; text-align:left">'0: No Care Level' '1: Care Level 1' '2: Care Level 2' '3: Care Level 3' '4: Care Level 3+'</td><td style = "width:17%; text-align:left">propNA: 0.01<br/></td></tr>
#> <tr><td style = "width:19%; text-align:left">nur_pst</td><td style = "width:9%; text-align:left">numeric</td><td style = "width:32%; text-align:left">Care level</td><td style = "width:23%; text-align:left">'1: Care Level 1' '2: Care Level 2' '3: Care Level 3/3+'</td><td style = "width:17%; text-align:left">propNA: 0.461<br/></td></tr>
#> </table></body></html>
if(interactive()){
df <- data.frame(var1 = 1:4,var2=5:8,var3=c('A','B','C','D'),
var4=as.factor(c('A','B','C','C')),var5=c(TRUE,TRUE,FALSE,FALSE))
#Demonstrating different options:
vtable(df,labels=c('Number 1','Number 2','Some Letters',
'Some Labels','You Good?'))
vtable(subset(df,select=c(1,2,5)),
labels=c('Number 1','Number 2','You Good?'),class=FALSE,values=FALSE)
vtable(subset(df,select=c('var1','var4')),
labels=c('Number 1','Some Labels'),
factor.limit=1,col.width=c(10,10,40,35))
#Different methods of applying variable labels:
labelsmethod2 <- data.frame(var1='Number 1',var2='Number 2',
var3='Some Letters',var4='Some Labels',var5='You Good?')
vtable(df,labels=labelsmethod2)
labelsmethod3 <- data.frame(a =c("var1","var2","var3","var4","var5"),
b=c('Number 1','Number 2','Some Letters','Some Labels','You Good?'))
vtable(df,labels=labelsmethod3)
#Using value labels and pre-labeled data:
library(sjlabelled)
df <- set_label(df,c('Number 1','Number 2','Some Letters',
'Some Labels','You Good?'))
df$var1 <- set_labels(df$var1,labels=c('A little','Some more',
'Even more','A lot'))
vtable(df)
#efc is data with embedded variable and value labels from the sjlabelled package
library(sjlabelled)
data(efc)
vtable(efc)
#Displaying the values of a character vector
data(USJudgeRatings)
USJudgeRatings$Judge <- row.names(USJudgeRatings)
vtable(USJudgeRatings,char.values=c('Judge'))
#Adding summary statistics for variable mean and proportion of data that is missing.
vtable(efc,summ=c('mean(x)','propNA(x)'))
}