I have seen this (Summarize different Columns with different Functions)
But in my situation, I want to use sum() with mpg, disp and hp. And use mean() with drat, wt and qsec.
All the function should be used with a group variable cyl.
Like this:
result.1 = mtcars %>% group_by(cyl) %>% summarise(across(.cols = c(mpg, disp, hp),
.fns = sum))
result.2 = mtcars %>% group_by(cyl) %>% summarise(across(.cols = c(drat:qsec),
.fns = mean))
final.result = full_join(result.1, result.2)
Is this possible that get final.result only use summarise() once.
Any help will be highly appreciated!