Learn R Programming

tables (version 0.9.31)

DropEmpty: DropEmpty pseudo-function

Description

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

Usage

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.

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.

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab