# Mean age grouped by sex and zone using `data.table` syntax
anxiety[, # No filtering (i)
list(mean_age = mean(age)), # Action to do (j)
list(sex, zone)] # Grouping vars (by)
# Mean PSQI score grouped by sex and zone, for those with
# an age greater than 18 AND a Beck score greater than 10.
anxiety[age > 18 & beck_global > 10,
list(mean_psqi = mean(pits_global)),
list(sex, zone)]
Run the code above in your browser using DataLab