pivot_wider_profile {decoupleR} | R Documentation

## Pivot a data frame to wider and convert it to matrix

### Description

Generates a kind of table where the rows come from `id_cols`, the columns from `names_from` and the values from `values_from`.

### Usage

    pivot_wider_profile(
      data,
      id_cols,
      names_from,
      values_from,
      values_fill = NA,
      to_matrix = FALSE,
      to_sparse = FALSE,
      ...
    )

### Arguments

`data` | A data frame to pivot.
`id_cols` | <`tidy-select`> A set of columns that uniquely identifies each observation. Defaults to all columns in `data` except for the columns specified in `names_from` and `values_from`. Typically used when you have redundant variables, i.e. variables whose values are perfectly correlated with existing variables.
`names_from` | <`tidy-select`> A pair of arguments describing which column (or columns) to get the name of the output column (`names_from`), and which column (or columns) to get the cell values from (`values_from`). If `values_from` contains multiple values, the value will be added to the front of the output column.
`values_from` | <`tidy-select`> A pair of arguments describing which column (or columns) to get the name of the output column (`names_from`), and which column (or columns) to get the cell values from (`values_from`). If `values_from` contains multiple values, the value will be added to the front of the output column.
`values_fill` | Optionally, a (scalar) value that specifies what each `value` should be filled in with when missing. This can be a named list if you want to apply different aggregations to different value columns.
`to_matrix` | Logical value indicating if the result should be a matrix. Parameter is ignored in case `sparse` is `TRUE`.
`to_sparse` | Logical value indicating whether the resulting matrix should be sparse or not.
`...` | Additional arguments passed on to methods.

### Details

In the current state of the function, to ensure its operation, the `id_cols` parameter is a single selector.

### Value

"widened" data; it is increasing the number of columns and decreasing the number of rows.

### Examples

    ## Not run:
    df <- tibble::tibble(
        tf = c("tf_1", "tf_1", "tf_2", "tf_2"),
        gene = c("gene_1", "gene_2", "gene_1", "gene_2"),
        mor = c(1, -1, 1, -1)
    )

    # Return a tibble
    pivot_wider_profile(
        data = df,
        id_cols = tf,
        names_from = gene,
        values_from = mor
    )

    # Return a matrix
    pivot_wider_profile(
        data = df,
        id_cols = tf,
        names_from = gene,
        values_from = mor,
        to_matrix = TRUE
    )
    # Return a sparse Matrix of class "dgCMatrix"
    pivot_wider_profile(
        data = df,
        id_cols = tf,
        names_from = gene,
        values_from = mor,
        to_sparse = TRUE
    )

    ## End(Not run)

[Package decoupleR version 2.0.1 Index]