Learn R Programming

evanverse (version 0.3.7)

df2list: Convert Data Frame to Named List by Grouping

Description

Group a data frame by one column and convert to named list. Each key becomes a list name; each value column becomes vector.

Usage

df2list(data, key_col, value_col, verbose = TRUE)

Value

A named list, where each element is a character vector of values.

Arguments

data

A data.frame or tibble to be grouped.

key_col

Character. Column name for list names.

value_col

Character. Column name for list values.

verbose

Logical. Whether to show message. Default = TRUE.

Examples

Run this code
df <- data.frame(
  cell_type = c("T_cells", "T_cells", "B_cells", "B_cells"),
  marker = c("CD3D", "CD3E", "CD79A", "MS4A1")
)
df2list(df, "cell_type", "marker")

Run the code above in your browser using DataLab