r8set() gives a table, a value of a new_table_type(), with columns added or replaced,
r8drop() without columns, and r8rename() with columns under other names. Each
gives a new value, which shares the columns it keeps, and leaves x as it is.
Arguments
- x
A value of a table.
- columns
r8set(): Named list, data frame, or table: The columns, each a vector with one element for each row, or acalc().r8drop(): Character or numeric: The columns, by name or by position, each once.- by
Optional Character or numeric: The key columns whose groups the aggregates of
calc()entries are over, by name or by position.- n_threads
Optional Integer [1, Inf): The threads that the work in Rust may use;
NULLtakesgetOption("r8.n_threads"), whose default is half the logical cores, at most 2 whereR CMD checklimits the cores, and at mostOMP_THREAD_LIMIT. A result is the same for any number of threads.- from
Character or numeric: The columns, by name or by position, each once.
- to
Character: The new names, one for each column of
from.
Value
A value of the type of x, or a Raven.
Columns of a declared table
A declared column that is replaced, and a column that takes its name, is checked, with the rules that read it. A table without a column that its type requires is a Raven, with the units and descriptions of the declaration.
Computed columns
An entry of columns that is a calc() is computed in Rust over the rows of
x as given, before any column changes. An aggregate in it is over all rows,
or, with by, over the rows of each row's group: r8set(x, list(n_ward = calc(n())), by = "ward") writes the size of each row's ward into the row.
Units and descriptions
A column that is added or replaced from a vector has none; one computed by
calc() has the unit that the expression infers, and no description. A renamed
column keeps its own.
Examples
r <- Raven(weight = c(60, 82), height = c(1.62, 1.80))
r <- r8set(r, list(bmi = r$weight / r$height^2))
r <- r8set(r, list(bmi2 = calc(weight / height^2)))
r <- r8rename(r, "weight", "mass")
r8drop(r, "height")#> <raven table> 2 rows ⨉ 3 columns
#> mass bmi bmi2
#> double double double
#> 1 60 22.86 22.86
#> 2 82 25.31 25.31