# indent_data_frame: Indents data.frames In atable: Create Tables for Reporting Clinical Trials

## Description

Indents data.frames for printing them as tables.

## Usage

 1 2 3 4 5 6 7 8 9 indent_data_frame( DD, keys, values = setdiff(colnames(DD), keys), character_empty = "", numeric_empty = NA, indent_character = "\\quad", colname_indent = "Group" ) 

## Arguments

 DD A data.frame. Should be sorted by keys with keys[1] varying slowest and keys[length(keys)] varying fastest. keys A character. Subset of colnames(DD) with length(keys)>=2. The combination of keys must be unique. DD[keys] must be class character or factor. values A character. Subset of colnames(DD). DD[keys] must be class character, factor or numeric. character_empty A character. Default ”. This character will be put in the new lines in class character columns. numeric_empty A numeric. Default NA. This character will be put in the new lines in class numeric columns. indent_character A character. character for one indent. Default is '\quad' (meant for latex). Can also be ' ' for Word. colname_indent A character. Default 'Group'. Name of the new column with the indented keys.

## Details

Squeeze multiple key-columns into one column and indents the values accordingly. Adds new lines with the indented keys to the data.frame. Meant for wide tables that need to be narrower and more 'readable' Meant for plotting with e.g. xtable::xtable or Hmisc::latex or officer::body_add_table. Look at the examples for a more precise description. Meant for left-aligned columns. Thats why the indent_character is inserted to the left of the original values.

## Value

A data.frame. Columns: c(colname_indent, values). Column colname_indent contains all combination of DD[keys], but now indented and squeezed in this column and casted to character. Columns 'values' contain all values of DD[values] unchanged. Number of rows is sum(cumprod(nlevels(DD[keys]))).

## Examples

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 DD <- expand.grid(Arm = paste0('Arm ', c(1,2,4)), Gender = c('Male', 'Female'), Haircolor = c('Red', 'Green', 'Blue'), Income = c('Low', 'Med', 'High'), stringsAsFactors = TRUE) DD <- doBy::orderBy(~ Arm + Gender + Haircolor + Income, DD) DD$values1 <- runif(dim(DD)[1]) DD$values2 <- 1 DD\$values3 <- sample(letters[1:4], size = nrow(DD), replace = TRUE) keys = c('Arm', 'Gender', 'Haircolor', 'Income') values = c('values1', 'values2', 'values3') ## Not run: DDD <- indent_data_frame(DD, keys, indent_character = ' ') # print both: Hmisc::latex(DD, file = '', longtable = TRUE, caption = 'Original table', rowname = NULL) Hmisc::latex(DDD, file = '', longtable = TRUE, caption = 'Indented table', rowname = NULL) ## End(Not run) 

atable documentation built on Dec. 16, 2020, 1:06 a.m.