How to group_by by only one factor level ?

Hi,
Is it possible to group_by() by only one selected level of the factor, like:

mtcars %>% group_by(cyl[2]) %>% summarise(n= n())

Let's sat I do not need other levels of the cyl.

You can just filter the values corresponding to this level and summarize across the data left. It would make no sense to summarize a part of the data and leave the rest unchanged, so Filtering and summarizing afterwards is the way to go.

Kind regards

I thought so but wasn't sure, now it makes sense. Thank you for your explanation.

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.