What is the most concise and/or elegant way to turn a vector into a single-row data frame in R? I'm trying to use a function that returns a 5-element vector and apply it across groups in my data frame, like so:
library(tidyverse)
mtcars %>%
group_by(cyl) %>%
group_map(~boxplot.stats(.$wt)$stats)
I'd like to have these results as rows in a new data frame, rather than a list of vectors, so I can plot with them in ggplot. But the best I've come up with is to add do.call(rbind, .) %>% as.data.frame to the end of my pipeline, which seems ungainly and inelegant. Replacing the group_map with a group_modify seems like the answer, but the function complains that my results aren't a data frame. And wrapping the anonymous function in a call to tibble_row doesn't work because tibble_row won't take vectors, just individual elements or explicit list columns.
Ideally, output would look like:
cyl V1 V2 V3 V4 V5
1 4 1.513 1.8850 2.200 2.6225 3.19
2 6 2.620 2.8225 3.215 3.4400 3.46
3 8 3.170 3.5200 3.755 4.0700 4.07
Surely there's a more elegant way to do what I'm trying to do, ideally within the tidyverse framework?