I am trying to look for the word 'dunk' in a column of NBA shot types as there are various types of dunks.
Then replace all the different dunk types with just the word 'dunk'
nbaClean2 <- nbaData %>%
select(x, y, points, type, result, team, player) %>%
filter(team == 'LAL', y <= 47) %>%
na_if("") %>%
drop_na() %>%
mutate(result = ifelse(result == 'missed', 'FGA', 'FGM')) %>%
mutate(dunk = gsub('\bdunk', 'dunk', type))
mutate(dunk = grepl('dunk', type), gsub('TRUE', 'dunk', dunk))
Essentially trying to see if I can use gsub() to partial match the word 'dunk'.
Trying to find a solution where I don't have to write all different types of shot types down if possible as there is a lot.