Split a data frame column containing a list into multiple columns using dplyr (or otherwise)

后端 未结 4 1632
面向向阳花
面向向阳花 2020-12-18 00:43

Consider the following example data

library(dplyr)
tmp <- mtcars %>%
    group_by(cyl) %>%
    summarise(mpg_sum = list(summary(mpg)))
4条回答
  •  遥遥无期
    2020-12-18 01:18

    As commented, you can also use the tidy function from package broom:

    library(broom)
    mtcars %>% group_by(cyl) %>% do(tidy(summary(.$mpg)))
    # Source: local data frame [3 x 7]
    # Groups: cyl [3]
    # 
    #     cyl minimum    q1 median  mean    q3 maximum
    #   (dbl)   (dbl) (dbl)  (dbl) (dbl) (dbl)   (dbl)
    # 1     4    21.4 22.80   26.0 26.66 30.40    33.9
    # 2     6    17.8 18.65   19.7 19.74 21.00    21.4
    # 3     8    10.4 14.40   15.2 15.10 16.25    19.2
    

提交回复
热议问题