Hello!
I've attached some code that does what I think you're looking for!
The first chunk just generates some data as you haven't provided any in your question.
The second does a group_by / summarise workflow, calculating the mean and standard deviation for each combination of country and age.
The third chunk uses filter to filter for US & Canada athletes who are 20 or under, pulls the time column (turns the column into a vector), then calculates the mean.
library(dplyr, warn.conflicts = F)
# generate data
set.seed(123)
dat <- tidyr::crossing(country = c("UK", "US", "AU", "CA", "NZ"),
age = c(10, 20, 30, 40, 50),
runner_id = LETTERS) %>%
mutate(time = rnorm(n = 650, mean = 200, sd = 15))
# get average times for all categories
avg_times <- dat %>%
group_by(country, age) %>%
summarise(time_mean = mean(time),
time_sd = sd(time))
#> `summarise()` has grouped output by 'country'. You can override using the
#> `.groups` argument.
head(avg_times)
#> # A tibble: 6 x 4
#> # Groups: country [2]
#> country age time_mean time_sd
#> <chr> <dbl> <dbl> <dbl>
#> 1 AU 10 199. 14.7
#> 2 AU 20 203. 12.4
#> 3 AU 30 200. 15.1
#> 4 AU 40 204. 11.6
#> 5 AU 50 196. 11.7
#> 6 CA 10 198. 17.8
# get 20 and under from CA and US
na_20_mean_time <- dat %>%
filter(country %in% c("CA", "US"),
age <= 20) %>%
pull(time) %>%
mean()
na_20_mean_time
#> [1] 200.9996
Created on 2022-03-27 by the reprex package (v2.0.1)