| 1 |
\name{compact01} |
| 2 |
\alias{compact01} |
| 3 |
\title{Compact Representation of Binary, 0/1 Values} |
| 4 |
\description{ |
| 5 |
Of a \code{0-1} i.e., binary vector, using \code{\link{symnum}(z == 1)}, |
| 6 |
produce a compact \dQuote{visual} \code{\link{character}} representation |
| 7 |
for human consumption. |
| 8 |
|
| 9 |
No rocket science, but a nice example of combining basic \R idioms. |
| 10 |
} |
| 11 |
\usage{ |
| 12 |
compact01(z, ncol = 50L) |
| 13 |
} |
| 14 |
\arguments{ |
| 15 |
\item{z}{a vector, typically of \code{0}s and \code{1}s, but more |
| 16 |
generally of \code{1}s and \dQuote{everything else} which you'd want to |
| 17 |
show visually. Inside \code{compact01(z, *)}, only \code{z == 1} is used.} |
| 18 |
\item{ncol}{a positive integer, specifying the number of \dQuote{columns} of the result.} |
| 19 |
} |
| 20 |
\value{ |
| 21 |
a \code{\link{character}} matrix \code{Ch}, \eqn{K \times 1}{K x 1}, |
| 22 |
where each row is a string of \code{"."} and \code{"|"} of string length |
| 23 |
typically \code{ncol}, but for short \code{z}, will have |
| 24 |
\code{\link{nchar}(Ch[1,1]) == min(ncol, length(z))}. |
| 25 |
} |
| 26 |
\author{Martin Maechler} |
| 27 |
\seealso{ |
| 28 |
\code{\link{symnum}} |
| 29 |
} |
| 30 |
\examples{ |
| 31 |
set.seed(12) |
| 32 |
z <- rbinom(120, size = 1, prob = 1/4) |
| 33 |
(compact01(z) -> Ch) |
| 34 |
compact01(z, 20) |
| 35 |
## "visualize" a TRUE/FALSE property |
| 36 |
x <- rnorm(150) |
| 37 |
compact01(abs(x) > 1.5) |
| 38 |
stopifnot(identical(0:1, dim(compact01(integer())))) |
| 39 |
} |
| 40 |
\keyword{utilities} |