How do you pivot data from a list of data frames in R?

前端 未结 3 1727
野趣味
野趣味 2021-01-25 05:22

Let\'s say I have a list of data frames ldf:

df1 <- data.frame(date = c(1,2), value = c(4,5))
df2 <- data.frame(date = c(1,2), value = c(4,5))
ldf <- li         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-25 05:56

    Another option is to use unnest from "tidyr" in conjunction with the typical grouping and aggregation functions via "dplyr":

    library(dplyr)
    library(tidyr)
    
    unnest(ldf) %>%
      group_by(date) %>%
      summarise(value = sum(value))
    # Source: local data frame [2 x 2]
    # 
    #   date value
    # 1    1     8
    # 2    2    10
    

提交回复
热议问题