gen.named.list | R Documentation |
Functions to transform patterns with placeholders into characters or into names of lists, vectors, data frames or matrices, based on variable ranges and additional conditions.
gen.named.list(.str, .expr, ...) gen.named.vector(.str, .expr, ...) gen.named.data.frame(.str, .expr, ..., byrow = FALSE) gen.named.matrix(.str, .expr, ..., byrow = FALSE)
.str |
A character, containing expressions to be evaluated in |
.expr |
A base expression containing free variables which is evaluated for all combinations of variables. |
... |
Arbitrary many variable ranges and conditions. |
byrow |
Logical. If |
The free variables in the inner expressions (i.e., the content of the {}
-brackets) of .expr
are evaluated in the same way as expressions in gen.list
.
See gen.list
for more details on the .expr
and ...
parameters.
These functions return lists, vectors, data frames, and matrices.
They work very similar to their counterparts without ".named".
Additionally the vector of characters, induced by .str
, serves as a vector of names for the generated structures.
In case of lists or vectors, the result is a named list or a named vector. For data frames and matrices, the names are taken as row names.
gen.list
for explanations on list and vector comprehension,
and listcompr for an overview of all list comprehension functions.
# sum up 1:i for i in 1:5 gen.named.list("sum_to_{x}", sum(1:x), x = 1:5) # matrix with named columns and rows gen.named.matrix("row{i}", gen.named.vector("col{j}", i+j, j = 1:3), i = 1:3) # a matrix where the expression refers to the rows and not the columns gen.named.matrix("col{i}", c(row1 = i, row2 = 10 * i, row3 = 100 * i), i = 1:10, byrow = TRUE)