Learn R Programming

ggvenn (version 0.1.19)

data_preparation: Utility functions for data type conversion between data.frame and list.

Description

Utility functions for data type conversion between data.frame and list.

Usage

data_frame_to_list(x)

list_to_data_frame(x)

Value

A list of sets or a data.frame with logical columns representing sets.

Arguments

x

A data.frame with logical columns representing sets, or a list of sets.

Examples

Run this code
# Convert data.frame to list
d <- dplyr::tibble(name = 1:6,
            A = c(rep(TRUE, 5), FALSE),
            B = rep(c(FALSE, TRUE), each = 3))
print(d)
data_frame_to_list(d)

# Convert list to data.frame
a <- list(A = 1:5, B = 4:6)
print(a)
list_to_data_frame(a)

# Round-trip conversion
identical(a, data_frame_to_list(list_to_data_frame(a)))  # TRUE
identical(d, list_to_data_frame(data_frame_to_list(d)))  # TRUE

Run the code above in your browser using DataLab