Helper function for lists of lists, where the top level list is over multiple samples, and the sublists are results that are identical across samples that one wishes to bind
Usage
bind_sublist(
toplist,
sublist,
what = c("rbind", "cbind", "c"),
.add_id = FALSE,
.id_name = "id"
)
Examples
toplist <- list(
sample_1 = list(
result1 = data.frame(
a = c(1, 2, 3),
b = c("X", "Y", "Z")
),
result2 = data.frame(
height = 180,
weight = 75
)
),
sample_2 = list(
result1 = data.frame(
a = c(6, 5, 4),
b = c("A", "B", "C")
),
result2 = data.frame(
height = 155,
weight = 60
)
)
)
bind_sublist(toplist, sublist = 1, what = "rbind", .add_id = TRUE)
#> id a b
#> 1 sample_1 1 X
#> 2 sample_1 2 Y
#> 3 sample_1 3 Z
#> 4 sample_2 6 A
#> 5 sample_2 5 B
#> 6 sample_2 4 C
bind_sublist(toplist, sublist = "result2", what = "rbind", .add_id = TRUE)
#> id height weight
#> 1 sample_1 180 75
#> 2 sample_2 155 60
bind_sublist(toplist, sublist = 2, what = "rbind", .add_id = FALSE)
#> height weight
#> 1 180 75
#> 2 155 60