Learn R Programming

easybio (version 1.2.2)

list2dt: Convert a List with Vector Values to a Long Data.table

Description

This function converts a named list with vector values in each element to a long data.table. The list is first flattened into a single vector, and then the data.table is created with two columns: one for the name of the original list element and another for the value.

Usage

list2dt(x, col_names = c("name", "value"))

Value

A long data.table with two columns: 'name' and 'value'.

Arguments

x

A named list where each element contains a vector of values.

col_names

The colnames of the returned result.

Examples

Run this code
library(easybio)
list2dt(list(a = c(1, 1), b = c(2, 2)))

Run the code above in your browser using DataLab