create boxplot with selected values

I'm trying to create a boxplot of the variable 'duration in seconds' over the categories 'age' from the dataset 'trips', but only including values of 'hours' less than 1 hour.
To create the boxplot:

boxplot(duration ~ agecat, data = trips)

However, how to only include hours < 1 hour??
?? [trips$hours < 1] ??

boxplot(trips$duration[trips$hours < 1] ~ trips$agecat)
gives the error
Error in stats::model.frame.default(formula = trips$duration[trips$hours <  : 
  variable lengths differ (found for 'trips$agecat')
boxplot(duration ~ agecat, data = trips[hours < 1])

gives the error

Error in `[.data.frame`(trips, hours < 1) : object 'hours' not found

boxplot(duration ~ agecat, data = trips[trips$hours < 1])
gives the error
Error in [.data.frame(trips, trips$hours < 1) :
undefined columns selected

Help is much appreciated!!

Try this.

boxplot(duration ~ agecat, data = trips[trips$hours < 1, ])

Notice the comma I added after hours < 1. It defines the selection of columns, all columns in this case.

Yes! That's it!
Many thanks FJCC!

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.