[.textTable {tablesgg} | R Documentation |
Extract a Subset of a texttable
Object
Description
Extract a subset of a textTable
object, creating a new table with
fewer and/or rearranged rows and columns.
Usage
## S3 method for class 'textTable'
x[i, j, drop=FALSE]
Arguments
x |
An object of S3 class |
i , j |
Logical or numeric indexing arguments used as subscripts with respect to the augmented row-column grid of the table. See DETAILS. |
drop |
Ignored (always treated as FALSE). |
Details
This function extracts, deletes, or rearranges subsets of the rows and
columns of a table. It is similar to subsetting an ordinary matrix, but
with restrictions required to ensure that the resulting object is still a
valid textTable
:
1. Indexing is with respect to the augmented row-column grid of the
table, in which all parts of the table (body, headers, and annotation) are
included. See ?textTable
for a description of table parts, and
?adim
for a description of the augmented grid. The summary
method for a textTable
shows the dimensions of each part.
2. The first index argument, i
, cannot itself be a matrix.
3. Indexing cannot be used to move rows or columns between different parts of the table (e.g. between body and headers, or between headers and annotation).
Helper functions arow
and acol
can be used to get the
augemented row and column numbers spanned by different table parts. See
the examples.
Value
An object of S3 class textTable
.
See Also
Examples
ttbl <- textTable(iris2_tab)
plot(ttbl)
# Remove the first column header row ("Flower part"), and reverse the
# order of the "Sepal" and "Petal" sets of columns:
subttbl <- ttbl[-1, c(1,2,5,6,3,4)]
plot(subttbl)
# Use helper functions 'arow', 'acol' to specify indices based on
# table structure:
i <- arow(ttbl, "colhead")[1] # row number of first column header row
j1 <- acol(ttbl, "rowhead") # column numbers for row header
j2 <- acol(ttbl, "colhead") # column numbers for column header
subttbl2 <- ttbl[-i, c(j1, j2[c(3,4,1,2)])]
identical(subttbl, subttbl2)