I have a tibble with this structure (dput
below):
# A tibble: 7 x 3
Date CC Variance_Type
<fct> <list> <list>
1 2-17 <dbl [8 x 2]> <chr [8]>
2 2-18 <dbl [8 x 2]> <chr [8]>
3 2-19 <dbl [8 x 2]> <chr [8]>
4 2-20 <dbl [8 x 2]> <chr [8]>
5 2-21 <dbl [8 x 2]> <chr [8]>
6 2-22 <dbl [8 x 2]> <chr [8]>
7 2-23 <dbl [8 x 2]> <chr [8]>
My desired output is a 56 row x 4 column tibble where:
- The items of the lists have been unnested each to their own row.
- The values in
Date
fill down the column to match the items that are presently in their row. - The columns of the nested tables in column
CC
are split into separate columns.
I've been trying to do this in the tidyverse with a combination of mutate(), map() and bind_rows() but I can't make it work. Any help is much appreciated.
The tibble:
structure(list(Date = structure(1:7, .Label = c("2-17", "2-18",
"2-19", "2-20", "2-21", "2-22", "2-23"), class = "factor"), CC = list(
structure(c(0.0292, 0.1803, 0.1063, 0.3555, 0.0227, 0.0471,
0.2588, 1, 2.92, 18.03, 10.63, 35.55, 2.27, 4.71, 25.88,
100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
))), structure(c(0.0414, 0.2307, 0.1813, 0.3428, 0.0408,
0.0137, 0.1494, 1, 4.14, 23.07, 18.13, 34.28, 4.08, 1.37,
14.94, 100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
))), structure(c(0.0348, 0.2298, 0.4534, 0.0453, 0.1252,
0.0406, 0.0709, 1, 3.48, 22.98, 45.34, 4.53, 12.52, 4.06,
7.09, 100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
))), structure(c(0.0693, 0.1241, 0.3104, 0.0885, 0.1706,
0.0563, 0.1807, 1, 6.93, 12.41, 31.04, 8.85, 17.06, 5.63,
18.07, 100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
))), structure(c(0.0431, 0.1621, 0.3896, 0.2243, 0.1005,
-0.0339, 0.1143, 1, 4.31, 16.21, 38.96, 22.43, 10.05, -3.39,
11.43, 100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
))), structure(c(0.0656, 0.1021, 0.2638, 0.1299, 0.2102,
0.0061, 0.2223, 1, 6.56, 10.21, 26.38, 12.99, 21.02, 0.61,
22.23, 100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
))), structure(c(0.0802, 0.1114, 0.6962, 0.0845, 0.1544,
-0.0958, -0.0309, 1, 8.02, 11.14, 69.62, 8.45, 15.44, -9.58,
-3.09, 100), .Dim = c(8L, 2L), .Dimnames = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ",
"Common to Jsc, and Uoc ", "Common to Jsc, and FF ",
"Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Coefficient", " % Total"
)))), Variance_Type = list(c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "), c("Unique to Jsc ",
"Unique to Uoc ", "Unique to FF ", "Common to Jsc, and Uoc ",
"Common to Jsc, and FF ", "Common to Uoc, and FF ", "Common to Jsc, Uoc, and FF",
"Total "))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -7L))