compact01: Compact Representation of Binary, 0/1 Values

View source: R/misc-goodies.R

compact01R Documentation

Compact Representation of Binary, 0/1 Values

Description

Of a 0-1 i.e., binary vector, using symnum(z == 1), produce a compact “visual” character representation for human consumption.

No rocket science, but a nice example of combining basic R idioms.

Usage

compact01(z, ncol = 50L)

Arguments

z

a vector, typically of 0s and 1s, but more generally of 1s and “everything else” which you'd want to show visually. Inside compact01(z, *), only z == 1 is used.

ncol

a positive integer, specifying the number of “columns” of the result.

Value

a character matrix Ch, K \times 1, where each row is a string of "." and "|" of string length typically ncol, but for short z, will have nchar(Ch[1,1]) == min(ncol, length(z)).

Author(s)

Martin Maechler

See Also

symnum

Examples

set.seed(12)
z <- rbinom(120, size = 1, prob = 1/4)
(compact01(z) -> Ch)
 compact01(z, 20)
## "visualize"  a TRUE/FALSE property
x <- rnorm(150)
compact01(abs(x) > 1.5)
stopifnot(identical(0:1, dim(compact01(integer()))))

sfsmisc documentation built on May 15, 2026, 9:06 a.m.