subset that collects data from x to y

Hello Rstudio community,
I have Data that reach from age 18-70. Now i want to subset it into groups that reach from 20-25, 25-30 and so on.
I tried:
Data20 <- subset(Data, Age <=18 & !>25 )
Data25 <-subset(Data,Age <=25 & !>30)
which creates the error unexpected token.

How do I solve this ?
Sincerely Herbert

To get rows where age is 20 - 25, inclusive, you would write

Data25 <-subset(Data,Age >= 20 & Age <= 25)

You might find the cut() function useful since you can set multiple break points and label all of the groups at once. The groups would remain in one data frame, which may or may not meet your needs.

1 Like

thx for the quick help :smiley:

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.