
Last chance! 50% off unlimited learning
Sale ends in
TableTree
Retrieve and assign elements of a TableTree
# S4 method for VTableTree,ANY,ANY,list
[(x, i, j, ...) <- value# S4 method for VTableTree,logical,logical
[(x, i, j, ..., drop = FALSE)
A TableTree
(or ElementaryTable
) object, unless a single cell was selected with drop = TRUE
, in which
case the (possibly multi-valued) fully stripped raw value of the selected cell.
(TableTree
)
a TableTree
object.
(numeric(1)
)
index.
(numeric(1)
)
index.
additional arguments. Includes:
keep_topleft
(flag
) ([
only) whether the top-left material for the table should be retained after
subsetting. Defaults to TRUE
if all rows are included (i.e. subsetting was by column), and drops it
otherwise.
keep_titles
(flag
) whether title information should be retained. Defaults to FALSE
.
keep_footers
(flag
) whether non-referential footer information should be retained. Defaults to
keep_titles
.
reindex_refs
(flag
) whether referential footnotes should be re-indexed as if the resulting subset is
the entire table. Defaults to TRUE
.
(list
, TableRow
, or TableTree
)
replacement value.
(flag
)
whether the value in the cell should be returned if one cell is selected by the
combination of i
and j
. It is not possible to return a vector of values. To do so please consider using
cell_values()
. Defaults to FALSE
.
By default, subsetting drops the information about title, subtitle, main footer, provenance footer, and topleft
.
If only a column is selected and all rows are kept, the topleft
information remains as default. Any referential
footnote is kept whenever the subset table contains the referenced element.
sort_at_path()
to understand sorting.
summarize_row_groups()
to understand path structure.
lyt <- basic_table(
title = "Title",
subtitles = c("Sub", "titles"),
prov_footer = "prov footer",
main_footer = "main footer"
) %>%
split_cols_by("ARM") %>%
split_rows_by("SEX") %>%
analyze(c("AGE"))
tbl <- build_table(lyt, DM)
top_left(tbl) <- "Info"
tbl
# As default header, footer, and topleft information is lost
tbl[1, ]
tbl[1:2, 2]
# Also boolean filters can work
tbl[, c(FALSE, TRUE, FALSE)]
# If drop = TRUE, the content values are directly retrieved
tbl[2, 1]
tbl[2, 1, drop = TRUE]
# Drop works also if vectors are selected, but not matrices
tbl[, 1, drop = TRUE]
tbl[2, , drop = TRUE]
tbl[1, 1, drop = TRUE] # NULL because it is a label row
tbl[2, 1:2, drop = TRUE] # vectors can be returned only with cell_values()
tbl[1:2, 1:2, drop = TRUE] # no dropping because it is a matrix
# If all rows are selected, topleft is kept by default
tbl[, 2]
tbl[, 1]
# It is possible to deselect values
tbl[-2, ]
tbl[, -1]
# Values can be reassigned
tbl[4, 2] <- rcell(999, format = "xx.x")
tbl[2, ] <- list(rrow("FFF", 888, 666, 777))
tbl[6, ] <- list(-111, -222, -333)
tbl
# We can keep some information from the original table if we need
tbl[1, 2, keep_titles = TRUE]
tbl[1, 2, keep_footers = TRUE, keep_titles = FALSE]
tbl[1, 2, keep_footers = FALSE, keep_titles = TRUE]
tbl[1, 2, keep_footers = TRUE]
tbl[1, 2, keep_topleft = TRUE]
# Keeps the referential footnotes when subset contains them
fnotes_at_path(tbl, rowpath = c("SEX", "M", "AGE", "Mean")) <- "important"
tbl[4, 1]
tbl[2, 1] # None present
# We can reindex referential footnotes, so that the new table does not depend
# on the original one
fnotes_at_path(tbl, rowpath = c("SEX", "U", "AGE", "Mean")) <- "important"
tbl[, 1] # both present
tbl[5:6, 1] # {1} because it has been indexed again
tbl[5:6, 1, reindex_refs = FALSE] # {2} -> not reindexed
# Note that order can not be changed with subsetting
tbl[c(4, 3, 1), c(3, 1)] # It preserves order and wanted selection
Run the code above in your browser using DataLab