Learn R Programming

matrixset (version 0.4.0)

annotate_from_matrix: Apply functions to a single matrix of a matrixset and store results as annotation

Description

This is in essence apply_row_dfw()/apply_column_dfw(), but with the results saved as new annotations. As such, the usage is almost identical to these functions, except that only a single matrix can be used, and must be specified (matrix specification differs also slightly).

Usage

annotate_row_from_apply(
  .ms,
  .matrix,
  ...,
  names_prefix = "",
  names_sep = "_",
  names_glue = NULL,
  names_sort = FALSE,
  names_vary = "fastest",
  names_expand = FALSE
)

annotate_column_from_apply( .ms, .matrix, ..., names_prefix = "", names_sep = "_", names_glue = NULL, names_sort = FALSE, names_vary = "fastest", names_expand = FALSE )

Value

A matrixset with updated meta info.

Arguments

.ms

matrixset object

.matrix

a tidyselect matrix name: matrix name as a bare name or a character.

...

expressions, separated by commas. They can be specified in one of the following way:

  • a function name, e.g., mean.

  • a function call, where you can use .m to represent the current matrix (for apply_matrix), .i to represent the current row (for apply_row) and .j for the current column (apply_column). Bare names of object traits can be used as well. For instance, lm(.i ~ program).

    The pronouns are also available for the multivariate version, under certain circumstances, but they have a different meaning. See the "Multivariate" section for more details.

  • a formula expression. The pronouns .m, .i and .j can be used as well. See examples to see the usefulness of this.

The expressions can be named; these names will be used to provide names to the results.

names_prefix, names_sep, names_glue, names_sort, names_vary, names_expand

See the same arguments of tidyr::pivot_wider()

Grouped <code>matrixset</code>

In the context of grouping, the apply_*_dfw() functions stack the results for each group value.

In the case of annotate_*_from_matrix(), a tidyr::pivot_wider() is further applied to ensure compatibility of the dimension.

The pivot_wider() arguments names_prefix, names_sep, names_glue, names_sort, names_vary and names_expand can help you control the final annotation trait names.

Details

A conscious choice was made to provide this functionality only for apply_*_dfw(), as this is the only version for which the output dimension is guaranteed to respect the matrixset paradigm.

On that note, see the section 'Grouped matrixset'.

See Also

annotate_row()/annotate_column().

Examples

Run this code
# This is the same example as in annotate_row(), but with the "proper" way
# of doing it
ms <- annotate_row_from_apply(student_results, "failure", mn = mean)

Run the code above in your browser using DataLab