gen.named.list {listcompr} | R Documentation |
Generate Named Lists, Vectors, Data Frames, and Matrices with List Comprehension
Description
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.
Usage
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)
Arguments
.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 |
Details
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.
Value
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.
See Also
gen.list
for explanations on list and vector comprehension,
and listcompr for an overview of all list comprehension functions.
Examples
# 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)