После группировки по 'playerID', получите индекс max
значение 'yearID', чтобы извлечь соответствующую ему 'зарплату' и обновите столбец 'salary' с помощью mutate
library(dplyr)
df1 %>%
group_by(playerID) %>%
mutate(salary = salary[which.max(yearID)])
# A tibble: 6 x 3
# Groups: playerID [2]
# playerID yearID salary
# <chr> <int> <int>
#1 abbotje01 1998 300000
#2 abbotje01 1999 300000
#3 abbotje01 2000 300000
#4 abbotje01 2001 300000
#5 abbotku01 1993 109000
#6 abbotku01 1994 109000
Или используя data.table
library(data.table)
setDT(df1)[, salary := salary[which.max(yearID)], playerID]
data
df1 <- structure(list(playerID = c("abbotje01", "abbotje01", "abbotje01",
"abbotje01", "abbotku01", "abbotku01"), yearID = c(1998L, 1999L,
2000L, 2001L, 1993L, 1994L), salary = c(175000L, 255000L, 255000L,
300000L, 109000L, 109000L)), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6"))