Skip to contents

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 identify each observation. Typically used when you have redundant variables, i.e. variables whose values are perfectly correlated with existing variables.

Defaults to all columns in data except for the columns specified through names_from and values_from. If a tidyselect expression is supplied, it will be evaluated on data after removing the columns specified through names_from and values_from.

names_from, 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 fill values 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.

Value

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

Details

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

Examples

if (FALSE) {
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
)
}