Home > Net >  Summarising multiple columns across multiple functions by group
Summarising multiple columns across multiple functions by group

Time:10-20

How can I write these two code together into one instead of having them separate? They work well but I would like to have them into one code. That is, have the total number of production and their average by task and department.

df %>%
    group_by(task, department) %>%                     
    summarise(across(.cols = c(production),
                  .fns = sum,
                   na.rm=T))                                     

df %>%
    group_by(task, department) %>%
    summarise(across(.cols = c(hours),
                     .fns = mean,                          
                     na.rm=T))

CodePudding user response:

df %>%
    group_by(task, department) %>%
    summarise(mean = mean(hours), sum = sum(production))
  • Related