Group by Summarize for large number of columns

Hello guys,

I am working with group by and summarize to aggregate my data. My columns are month list (approx 50 month in history), which I need to sum aggregate.. What I know is manually sum each columns in dplyr... For example ( dplyr:: summarise(col1 = sum(col1), col2 = sum(col2)).... which is painful to do for 50+ columns. Is there a way if I specify start and ending column number, the algorithm itself take care of the process.



look at across()


iris %>%
  group_by(Species) %>%
  summarise(across(where(is.numeric), ~ sum(.x, na.rm = TRUE)))
1 Like

summarize_if() or summarize_at() are how I do this.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.