Lbrk.textTable: Extract a Subset of a 'texttable' Object

Description Usage Arguments Details Value See Also Examples

Description

Extract a subset of a textTable object, creating a new table with fewer and/or rearranged rows and columns.

Usage

1
2
## S3 method for class 'textTable'
x[i, j, drop=FALSE]

Arguments

x

An object of S3 class textTable, representing a 2D table.

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

textTable, adim, arow, acol

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)
  

tablesgg documentation built on June 3, 2021, 1:06 a.m.