Subgroups in a column

Hi. I have a dataset where the column 'age' has values from 19 to 67.
I wanted to create 3 main subgroups:
young (19-30)
middle aged (30-50)
over fifty (50+)

I wrote

young <- beauty$age <= 30
middle.aged <- beauty$age >= 31 & beauty$age <= 50
over.fifty <- beauty$age >= 51

but it returns only TRUE or FALSE.
I wanted to saw them under the 'age' category, so that when I call it it doesn't return me the initial values but these three groups.
I need to do a contingency table and a graph and I need to visualize them in this way in order to see the relationship with another variable

Thank you

I recommend dplyr::case_when for your needs

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.