A list of dataframes:
mydiamonds <- diamonds %>%
group_by(cut, color) %>%
mutate(cumprice = cumsum(price)) %>%
mutate(lag_cumprice = lag(cumprice)) %>%
na.omit(.) %>%
group_split %>%
map(~ list(dta = ., initial_val = min(.$cumprice)))
If this was a list of just dataframes and nothing else, I think I could combine them into one dataframe with just:
mydiamonds %>% bind_rows %>% glimpse
However, this gives error:
Error: Internal error in `vec_assign()`: `value` should have been recycled to fit `x`.
Presumably because it's not a straightforwards list of dataframes since each list item has both a df and a numeric value:
mydiamonds[[1]]
$dta
# A tibble: 162 x 12
carat cut color clarity depth table price x y z cumprice lag_cumprice
<dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <int> <int>
1 0.71 Fair D VS2 56.9 65 2858 5.89 5.84 3.34 5706 2848
2 0.9 Fair D SI2 66.9 57 2885 6.02 5.9 3.99 8591 5706
3 1 Fair D SI2 69.3 58 2974 5.96 5.87 4.1 11565 8591
4 1.01 Fair D SI2 64.6 56 3003 6.31 6.24 4.05 14568 11565
5 0.73 Fair D VS1 66 54 3047 5.56 5.66 3.7 17615 14568
6 0.71 Fair D VS2 64.7 58 3077 5.61 5.58 3.62 20692 17615
7 0.91 Fair D SI2 62.5 66 3079 6.08 6.01 3.78 23771 20692
8 0.9 Fair D SI2 65.9 59 3205 6 5.95 3.94 26976 23771
9 0.9 Fair D SI2 66 58 3205 6 5.97 3.95 30181 26976
10 0.9 Fair D SI2 64.7 54 3205 6.1 6.04 3.93 33386 30181
# … with 152 more rows
$initial_val
[1] 5706
Is there a way I can tell bind_rows() to only use the $dta part of each list item?