Попробуйте следующее:
library(tidyverse)
#Data
df <- structure(list(team_id = c("Red", "Blue", "Yellow", "Red", "Blue",
"Yellow"), date = c("18/01/20", "18/01/20", "19/01/20", "19/01/20",
"20/01/20", "20/01/20"), points_for = c(16L, 12L, 10L, 9L, 17L,
13L), points_against = c(12L, 16L, 9L, 10L, 13L, 17L)), class = "data.frame", row.names = c(NA,
-6L))
#Code
df %>% group_by(team_id) %>% mutate(total_points_for=sum(points_for,na.rm=T),
total_points_against=sum(points_against,na.rm=T))
# A tibble: 6 x 6
# Groups: team_id [3]
team_id date points_for points_against total_points_for total_points_against
<chr> <chr> <int> <int> <int> <int>
1 Red 18/01/20 16 12 25 22
2 Blue 18/01/20 12 16 29 29
3 Yellow 19/01/20 10 9 23 26
4 Red 19/01/20 9 10 25 22
5 Blue 20/01/20 17 13 29 29
6 Yellow 20/01/20 13 17 23 26