DropEmpty: 'DropEmpty' pseudo-function

Description Usage Arguments Details Pseudo-functions Examples

Description

Pseudo-function to indicate that rows or columns containing no observations should be dropped.

Usage

1
DropEmpty(empty = "", which = c("row", "col", "cell"))

Arguments

empty

String to use in empty cells.

which

A vector indicating what should be dropped. See the Details below.

Details

If the which argument contains "row", then any row in the table in which all cells are empty will be dropped. Similarly, if it contains "col", empty columns will be dropped. If it contains "cell", then cells in rows and columns that are not dropped will be set to the empty string.

Pseudo-functions

This is a “pseudo-function”: it takes the form of a function call, but is never actually called: it is handled specially by tabular.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
df <- data.frame(row = factor(1:10), value = rnorm(10))
subset <- df[sample(10, 5),, drop = FALSE]

# Some rows did not get selected, so this looks ugly
tabular(row ~ value*mean, data = subset)

# This only shows rows with data in them
tabular(row*DropEmpty() ~ value*mean, data = subset)

# This shows empty cells as "(empty)"
tabular(row*DropEmpty("(empty)", "cell") ~ value*mean, data = subset)

Example output

Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

             
     value   
 row mean    
 1    1.22047
 2        NaN
 3   -2.38012
 4   -0.03349
 5        NaN
 6        NaN
 7    0.41958
 8        NaN
 9    1.26050
 10       NaN
             
     value   
 row mean    
 1    1.22047
 3   -2.38012
 4   -0.03349
 7    0.41958
 9    1.26050
             
     value   
 row mean    
 1    1.22047
 2   (empty) 
 3   -2.38012
 4   -0.03349
 5   (empty) 
 6   (empty) 
 7    0.41958
 8   (empty) 
 9    1.26050
 10  (empty) 

tables documentation built on Oct. 23, 2020, 5:21 p.m.