Aggregate with multiple functions

I want to use aggregate() to group my models of cars in my data.
I used this code to get an averages for one column. It gave me averages for all numerical columns.

aggregate(x,
               by = list(x$`Model Name`),
               FUN = mean)

Now, how do I edit this code to pick which columns I want to average and which columns I want to SUM?
This code averages everything by grouping them by 'Model Name'. I want some columns to use FUN=mean and some FUN=SUM

Actually, Can this be done with summarize() ?

Never mind, I got it using summarize(),

Would you mind sharing your code and marking it as a solution for your question? This can be helpful to others facing the same issue and looking for help.

Solution:

x %>%
summarize(Units_Sold = sum(Units),
            Average_Profit = mean(Average_Gross),
            Total_Gross = sum(Total_Gross))
1 Like

This topic was automatically closed 7 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.