Summarize multiple filter groups

I am new to this place, so I hope I'm doing things the right way.
I'm having soms trouble to summarize multiple filtergroups, and am looking for some help.
I looked at the other topics, but can't seem to find a matching one for my problem.

I have a dataset consisting of multiple columns, but the 2 important for this task are age_buyer and selling_price.
I would like to summarize for tha ages 18-35, 36-50, 51-80.
For example I made 3 groups using this code:

age_18_35 <- Dataset %>%
     filter(between(age_buyer,18,35))

What I would like it to summarize for all 3 groups age_18_35, age_36_50, age_51_80, and summarize like this.

summarize(Mean=mean(selling_price), Max=max(selling_price), Min=min(selling_price))

I can do this for 1 filter, and this work perfect, but can't seem to figure out how to do this in 1 line of code for all 3? Any help would be appreciated.

Hello.
Thanks for providing code , but you could take further steps to make it more convenient for other forum users to help you.

Share some representative data that will enable your code to run and show the problematic behaviour.

You might use tools such as the library datapasta, or the base function dput() to share a portion of data in code form, i.e. that can be copied from forum and pasted to R session.


In advance of that, I would suggest that there is no need to filter your original dataset, rather use mutate() and case_when() to assign appropriate group labels, this will then be leveraged in the following summarize().

1 Like

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.