Identify runs of repeated values in a matrix of row or columns headers. Detection of runs respects the hierarchical structure of headers. This is an internal utility function, not intended to be called by package users.
headerRuns(x, which_head)
A list with one component per header variable in x
. Each component
is a data frame. The i
-th data frame has one row per run of values
in the i
-th header variable, with columns:
Header layer number, increasing from innermost (most deeply nested) to
outermost. Thus for "row" headers it is the reverse of column number in
x
(ncol(x) - i + 1
), and for "col" headers it is the reverse
of row number in x
(nrow(x) - i + 1
).
Run number within the layer. Levels are numbered from 1, so this column is just the sequence from 1 to the number of rows in the data frame.
The value in x
associated with the run.
Position in x
where the run starts (row number for "row" headers,
column number for "col" headers).
Length of the run (number of rows or columns).
If x
is NULL, the returned value is also NULL. If x
has no
header variables, the returned value is an empty list, list()
.
A matrix containing table row or column headers.
Character scalar, "row" or "col", indicating whether x
contains row
headers or column headers. "row" means that each column corresponds to
one header variable or layer, ordered from outermost to innermost, left to
right (i.e., as the header would be displayed). "col" means that each
_row_ corresponds to one header variable, ordered from outermost (top) to
innermost (bottom), again as the header would be displayed.
Runs are defined cumulatively across header variables. For the outermost
variable, runs consist of consecutive duplicated values in the first
column/row of x
; for the second-outermost variable, runs are
defined by consecutive duplicated values in the first two columns/rows of
x
, and so on. (That is, the header variables are treated as a
hierarchy, with inner variables nested within outer ones.)